ZOJ Problem Set - 1013 Great Equipment ()

ZOJ Problem Set - 1013

Great Equipment


Time Limit: 10 Seconds      Memory Limit: 32768 KB


Once upon a time, there lived Catherine Ironfist, the Queen of Enroth. One day, she received the news of her father‘s death. So she sailed for Erathia to attend her father‘s funeral. Fearing the worst, she assembled a military fleet as her escort. On reaching the coast of Erathia, Catherine found an allied wizard‘s tower, devastated from battle and abandoned. There she learned that a black-hearted knight poisoned her father using a goblet of wine, and Erathia was falling to the enemies. And then, she mustered local armies, and marched to Erathia‘s castle, restoring lost land along the way.

During the battles, she found that the equipments for the soldiers were in urgent
need. And she knew clearly that the best equipments were made by the battle
dwarf‘s workshop in the world. The workshop‘s equipments were well known for
the firmness and top-quality. "Cloak of the Undead King", "Armor
of the Damned", "Angelic Helm" are the nonesuch ones. But unfortunately,
the workshop was seated at the Erathia‘s castle, the territory under the enemy‘s
control. So she sent a brave volunteer to come into the castle and asked for
the workshop‘s help.

"It‘s our pleasure to help the righteous heroine." Rion, the leader
of the workshop sent the message to Catherine, " We haven‘t enough resources
to build the nonesuch equipments. So we‘ll try to offer the ordinary equipments
as more as possible. Still, those ones are much better the equipments made by
other workshops. But we have faced a difficult problem. The castle is in a state
of siege. The guards prohibited the equipments to be carried away from the castle.
We have to ask for the trade caravans‘ help. As you know, each trade caravan‘s
capability of carrying equipments is limited. If they had carried a little more,
they would be detected by the guards, which would lead them into the prison.
So you have to arrange how to carry these equipments."

The workshop would offer helms, armors and boots. These three ones had different
defend capabilities. Also, their weight and size were different from each other.
What‘s more, Rion had told Catherine that if armed with those three ones together,
they would form a set of equipments, which might provide much more defend capability.
As far as the trade caravan was concerned, each one had its special weight limitation
and size limitation. Catherine had to make the decision on how to arrange the
transportation plan to provide her soldiers as more defend capabilities as possible.
Could you help her to finish the plan?

Input

The input describes several test cases. The first line of input for each test
case contains a single integer n, the number of trade caravans (0 <= n <= 100).

The following four lines describe the information of those equipments. The first
line contains three integers w1, s1 and d1, indicating the weight, size and
defend capabilities of the helm. The integers w2, s2 and d2 in the second line
represent the weight, size and defend capabilities of the armor. Also, in the
third line, w3, s3 and d3 are the weight, size and defend capabilities of the
boot. The fourth line contains four integers c1, c2, c3 and d4. Among those
integers, c1, c2, c3 are the number of helms, armors and boots in a set of equipments,
d4 is the capability of this set.

In the test case, following those data are n lines, describing the carrying
capabilities of the trade caravans. Each line contains two integers, xi and
yi, indicating the weight limit and size limit of a trade caravan.

The input is terminated by a description starting with n = 0. This description
should not be processed.

Note: Because of the trade caravans‘ carrying capabilities, you may assume the
quantities of the helms, armors and boots will not exceed 500 respectively.

Output

Your program must compute the defend capability of the best carrying plan. That
is, after having performed the carrying plan, the defend capability of the equipments
which have been carried away from the castle should be the largest. For each
test case in the input file, print the case number and a colon, and then the
defend capability of those equipments.

Print a blank line between test cases.

Sample Input

3

1 1 3

5 6 10

2 1 2

1 1 1 50

1 1

5 6

2 1

0

Output for the Sample Input

Case 1: 50



Source: Asia 2001, Shanghai (Mainland China)

另一种解法:https://www.cnblogs.com/acliang/p/4847669.html

#include <iostream>
#include <algorithm>

using namespace std ; 

#define maxn 501
int n , w1 , s1 , d1 , w2 , s2 , d2 , w3 , s3 , d3 ,
    c1 , c2 , c3 , d4 , x , y ; 

int car[2][maxn] ;
int dp1[maxn][maxn] , dp2[maxn][maxn] ;
int num1 , num2 ; 

int compute(int a , int b , int c){
    int min_num = min(a/c1 , min(b/c2 , c/c3)) ;
    return (min_num * d4 + (a - min_num * c1)*d1 + (b - min_num * c2)*d2
            + (c - min_num * c3)*d3) ;
}

int resolve(){
    int result = 0 ;
    for(int i=0 ; i<=num1 ; i++){
        for(int j=0 ; j<=num2 ; j++){
            if(dp2[i][j] >= 0)
            result = max(result , compute(i , j , dp2[i][j])) ;
        }
    }
    return result ;
}

int main(){
    int Case = 0 ;
    while(cin >> n && n ){
        Case ++ ;
        cin >> w1 >> s1 >> d1
            >> w2 >> s2 >> d2
            >> w3 >> s3 >> d3
            >> c1 >> c2 >> c3 >> d4 ; 

        for(int i=0 ; i<n ; i++){
            cin >> x >> y ;
            car[0][i] = x ;
            car[1][i] = y ;
        }
        for(int i=0 ; i<maxn ; i++){
            for(int j=0 ; j<maxn ; j++){
                dp1[i][j] = dp2[i][j] = -1 ;
            }
        }
        // 初始化状态
        num1 = num2 = 0 ;
        dp2[0][0] = 0 ;
        int pos = 0 ;
        while(pos < n){// 第pos辆车

            for(int i=0 ; i<=num1 ; i++){
                for(int j=0 ; j<= num2 ; j++){
                    dp1[i][j] = dp2[i][j] ;
                    dp2[i][j] = -1 ;
                }
            }
            int re_a = min(car[0][pos]/w1 , car[1][pos]/s1) ;
            for(int i=0 ; i<=re_a ; i++){
                int re_aw = car[0][pos] - i * w1 ;
                int re_as = car[1][pos] - i * s1 ;
                int re_b = min(re_aw/w2 , re_as/s2) ;
                for(int j=0 ; j<=re_b ; j++){
                    int re_bw = re_aw - j * w2 ;
                    int re_bs = re_as - j * s2 ;
                    int re_c = min(re_bw/w3 , re_bs/s3) ;
                    for(int x = 0 ; x<=num1 ; x++){
                        for(int y=0 ; y<=num2 ; y++){
                            if(dp1[x][y]>=0 && dp1[x][y] + re_c > dp2[x+i][y+j]){
                                dp2[x+i][y+j] = dp1[x][y] + re_c ;
                            }
                        }
                    }
                }
            }
            num1 += min(car[0][pos]/w1 , car[1][pos]/s1) ;
            num2 += min(car[0][pos]/w2 , car[1][pos]/s2) ;
            pos ++ ;
        }
        int result = resolve() ; 

        if(Case != 1){
            cout << endl ;
        }
        cout << "Case " << Case << ": " << result << endl ;
    }
    return 0 ;
}

# include<stdio.h>
# include<memory.h>
# define MAXN 501
int dp[MAXN][MAXN],dp2[MAXN][MAXN];
int car[2][100];    //car[0][i]、car[1][i] 分别表示第i辆车的能承受的重量、体积
int n;    //车的数量
int w1,w2,w3,s1,s2,s3,c1,c2,c3,d1,d2,d3,d4;

int min(int a,int b){
    return a<b ? a :b;
}

int compute(int a,int b,int c){    //计算防御能力
    int minnum;
    minnum = min(min(a/c1,b/c2),c/c3);
    return (minnum * d4 + (a- minnum*c1)*d1 + (b- minnum*c2)*d2 + (c- minnum*c3)*d3);
}

int main(){
    int i,j,k,cas=0,x,y;
        int curr_a,curr_b; //分别表示所有车全部装头盔、全部装盔甲 的最大数量
        while(scanf("%d",&n)==1 && n){
            scanf("%d%d%d%d%d%d%d%d%d%d%d%d%d",
                &w1, &s1, &d1,
                &w2, &s2 ,&d2,
                &w3, &s3, &d3,
                &c1, &c2, &c3, &d4);
            for(i=0;i<n;i++) scanf("%d%d",&car[0][i],&car[1][i]);
            for(i=0; i<MAXN; i++)
                for(j=0; j<MAXN; j++)
                    dp[i][j] = dp2[i][j] = -1;
            curr_a = curr_b = 0;
            dp2[0][0] = 0;
            k = 0;
            while(k < n){
                for(i=0; i<= curr_a; i++){
                    for(j=0; j<=curr_b; j++){
                        dp[i][j] = dp2[i][j];
                        dp2[i][j] = -1;
                    }
                }
                int r_a =min(car[0][k] / w1, car[1][k] / s1);    //该车能够装头盔数量的最大值
                for(i=0; i<=r_a; i++)
                {
                    int r_aw = car[0][k] - i * w1;    //装了头盔后剩下的总重量
                    int r_as = car[1][k] - i * s1;    //装了头盔后剩下的总体积
                    int r_b = min(r_aw / w2, r_as / s2);    //该车剩下部分能够装盔甲数量的最大值
                    for(j=0; j<=r_b; j++)
                    {
                        int r_bw = r_aw - j * w2;    //再装盔甲后剩下的总重量
                        int r_bs = r_as - j * s2;    //再装盔甲后剩下的总体积
                        int r_c = min(r_bw / w3,r_bs/s3);    //该车剩余部分最多能装战靴的数量
                        for(x=0; x<=curr_a; x++)
                            for(y=0; y<=curr_b; y++)
                                if(dp[x][y] >=0 && dp[x][y] + r_c >dp2[x+i][y+j])
                                    dp2[x+i][y+j] = dp[x][y] +r_c;
                    }
                }
                curr_a += min(car[0][k] / w1, car[1][k] / s1);
                curr_b += min(car[0][k] / w2, car[1][k] / s2);
                k++;
            }

            int ans =0;
            for(i=0; i<=curr_a; i++)
                for(j=0; j<=curr_b; j++)
                if(dp2[i][j] != -1){
                    int temp = compute(i,j,dp2[i][j]);
                    if(temp > ans) ans = temp;
                }
            if(cas>0) puts("");
            printf("Case %d: %d\n", ++cas, ans);
        }
        return 0;
}

原文地址:https://www.cnblogs.com/yi-ye-zhi-qiu/p/9164755.html

时间: 2024-10-29 13:43:35

ZOJ Problem Set - 1013 Great Equipment ()的相关文章

ZCMU Problem H: Crixalis&#39;s Equipment(贪心,排序)

#include<stdio.h> #include<stdlib.h> struct node { int a,b; }c[1002]; int cmpxy(const struct node *c,const struct node *d) { return (d->b - d->a) - (c->b - c->a); } int main() { int n,i,v,t,flag; // freopen("a.txt","

ZOJ 1151 Word Reversal反转单词 (string字符串处理)

链接:http://acm.zju.edu.cn/onlinejudge/showProblem.do?problemId=151 For each list of words, output a line with each word reversed without changing the order of the words. This problem contains multiple test cases! The first line of a multiple input is

hdu 3177 Crixalis&#39;s Equipment(贪心)

Problem Description Crixalis - Sand King used to be a giant scorpion(蝎子) in the deserts of Kalimdor. Though he's a guardian of Lich King now, he keeps the living habit of a scorpion like living underground and digging holes. Someday Crixalis decides

ZOJ 1639 Hang Up the System (状态压缩)

Hang Up the System Time Limit: 2 Seconds      Memory Limit: 32768 KB You're going to design a multi-task operating system for an embedded system. Because the resources are limited on this mini computer, parallel running of some programs will probably

[HDU] 3177.Crixalis&#39;s Equipment (贪心)

Problem Description 题目大意: 有V的空间以及N个物品,对于放入每个物品有Ai(放入物品后剩余空间的减少大小),Bi(放入该物品之前需要的最小剩下空间大小,如果大于当前剩余空间大小则无法放入) Input T组数据,每组数据有N+1行,每组数据第一行输入V,N,之后的N行每行描述一个物品的Ai,Bi 0<T<= 10, 0<V<10000, 0<N<1000, 0 <Ai< V, Ai <= Bi < 1000. Output

Android Studio编译运行Fresco Sample。Android缓存新境界。 (a problem occurred start process &#39;command &#39;ndk-build&#39;&#39;)

今天闲逛知乎,偶遇一篇“Android应用开发难点”,作为安卓程序猿,本能点进去,想看看究竟能有什么难点自己不知道的(夜郎自大..面壁中). 插件化,H5容器优化,网络.图片缓存..感觉都还好.直到看到“Fresco出来之前,你是不是觉得图片缓存已经到头了?” Fresco究竟是何方神圣!! 询问度娘得知,2015.3.27日之前就已经发布了(度娘的结果最早是3.27).通过查看GitHub: Version 0.1.0  tyronen released this 16 days ago · 

Problem A: 英雄无敌3(1)【dp/待补】

Problem A: 英雄无敌3(1) Time Limit: 1 Sec  Memory Limit: 128 MBSubmit: 86  Solved: 16[Submit][Status][Web Board] Description 大家知道在英雄无敌3中,每个城堡都需要钱来维持建设,现在有一座很奇怪的金矿,它在第i天只产生si 元的钱,而且如果你在第i天拿到si 元的钱,那么你将在 xi 内(包括第i天)拿不到钱,而在yi天内(包括第i天)一定要再次拿钱.现在有一个着急的玩家,他现在已

KMP(http://acm.sdut.edu.cn/sdutoj/problem.php?action=showproblem&amp;problemid=2772)

#include <stdio.h>#include <string.h>#include <stdlib.h>char a[1000001],b[1000001];int next[1000001];int l,l2;void Getnext(){ int i=0; int j=-1; next[0]=-1; while(i<l2) { if(-1==j||b[i]==b[j]) { i++; j++; next[i]=j; } else j=next[j];

zoj 3781 Paint the Grid Reloaded (比较隐含的最短路)

Paint the Grid Reloaded Time Limit: 2 Seconds      Memory Limit: 65536 KB Leo has a grid with N rows and M columns. All cells are painted with either black or white initially. Two cells A and B are called connected if they share an edge and they are