zoj1013 2010.7.28

zoj1013 2010.7.28

Great Equipment

 

--------------------------------------------------------------------------------

 

Time Limit: 10 Seconds      Memory Limit: 32768 KB

 

--------------------------------------------------------------------------------

 

Once upon a time, there lived CatherineIronfist, the Queen of Enroth. One day, she received the news of her father'sdeath. So she sailed for Erathia to attend her father's funeral. Fearing theworst, she assembled a military fleet as her escort. On reaching the coast ofErathia, Catherine found an allied wizard's tower, devastated from battle andabandoned. There she learned that a black-hearted knight poisoned her father usinga goblet of wine, and Erathia was falling to the enemies. And then, shemustered local armies, and marched to Erathia's castle, restoring lost landalong the way.

 

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

 

"It's our pleasure to help therighteous heroine." Rion, the leader of the workshop sent the message toCatherine, " We haven't enough resources to build the nonesuch equipments.So we'll try to offer the ordinary equipments as more as possible. Still, thoseones are much better the equipments made by other workshops. But we have faceda difficult problem. The castle is in a state of siege. The guards prohibitedthe equipments to be carried away from the castle. We have to ask for the tradecaravans' help. As you know, each trade caravan's capability of carryingequipments is limited. If they had carried a little more, they would bedetected by the guards, which would lead them into the prison. So you have toarrange how to carry these equipments."

 

The workshop would offer helms, armors andboots. These three ones had different defend capabilities. Also, their weightand size were different from each other. What's more, Rion had told Catherinethat if armed with those three ones together, they would form a set ofequipments, which might provide much more defend capability. As far as thetrade caravan was concerned, each one had its special weight limitation andsize limitation. Catherine had to make the decision on how to arrange thetransportation plan to provide her soldiers as more defend capabilities aspossible. Could you help her to finish the plan?

 

 

Input

 

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

 

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

 

In the test case, following those data aren lines, describing the carrying capabilities of the trade caravans. Each linecontains two integers, xi and yi, indicating the weight limit and size limit ofa trade caravan.

 

The input is terminated by a descriptionstarting 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 andboots will not exceed 500 respectively.

 

 

Output

 

Your program must compute the defendcapability of the best carrying plan. That is, after having performed thecarrying plan, the defend capability of the equipments which have been carriedaway from the castle should be the largest. For each test case in the inputfile, print the case number and a colon, and then the defend capability ofthose 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 (MainlandChina)

 

 

 

题目大意是说有3种武器,每种都有一个重量w,一个尺寸s,一个战斗系数d,另外,如果把数量分别为c1,c2,c3的3种武器合在一起用,就会得到战斗系数为d4的新武器。

现在,有1,2,3...,n量车子来运输武器,每量车子都有最大运输重量和最大运输尺寸,现在用车量来运输武器,要求出能达到的最大战斗系数。

 

这题很明显是一道动态规划题,初看题意感觉跟背包问题挺象的,不过那只是表面现象而已。

设f[i][n1][n2]表示用前i量车子在运 n1件1武器和n2件2武器的条件下能运的第3种武器的最大数量。

那么f[0][0][0]=0

设函数num(i,j,k)表示第i量车子在运j个1武器和k个2武器后最多再能运k个3武器,则

f[i][n1][n2]=f[i-1][n3][n4]+num(i,n1-n3,n2-n4)

具体参数的取值范围详见程序。

另外可以看到f[i]的值只于f[i-1]有关,那么可以用滚动数组来节省空间。

算出f[n]后,就可以枚举i,j了,看f[n][i][j]的情况,算出此情况下的战斗系数,这样就可以求出最大值了。


#include <cstdio>
#include <cstring>
#include <iostream>

using namespace std;

#define MAXN 510

int pre[MAXN][MAXN],now[MAXN][MAXN];
int w1,s1,d1,w2,s2,d2,w3,s3,d3,c1,c2,c3,d4,n;
int ma,mb;

int main()
{
	int cas=0;
	while (scanf("%d",&n),n)
	{
		cas++;
		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);
		memset(pre,255,sizeof(pre));
		d4=d4-(c1*d1+c2*d2+c3*d3);
		pre[0][0]=0;
		ma=mb=0;
		for(int i=0;i<n;i++)
		{
			memset(now,255,sizeof(now));
			int cw,cs;
			scanf("%d %d",&cw,&cs);
			int maa=ma,mbb=mb;
			for(int i1=0;i1<=maa;i1++)
				for(int j1=0;j1<=mbb;j1++)
				{
					if (pre[i1][j1]<0) continue;
					for(int i11=i1,tw1=0,ts1=0;tw1<=cw&&ts1<=cs;i11++,tw1+=w1,ts1+=s1)
						for(int j11=j1,tw2=tw1,ts2=ts1;tw2<=cw&&ts2<=cs;j11++,tw2+=w2,ts2+=s2)
						{
							if(ma<i11) ma=i11;
							if(mb<j11) mb=j11;
							int da=(cw-tw2)/w3;
							int db=(cs-ts2)/s3;
							if (da>db) da=db;
							if (now[i11][j11]<pre[i1][j1]+da)
								now[i11][j11]=pre[i1][j1]+da;
						}
				}
				for(int i11=0;i11<=ma;i11++)
					for(int j11=0;j11<=mb;j11++)
						pre[i11][j11]=now[i11][j11];
		}
		int max=0;
		for(int i=0;i<=ma;i++)
			for(int j=0;j<=mb;j++)
			{
				if(now[i][j]<0)continue;
				int t=i*d1+j*d2+now[i][j]*d3;
				int a=i/c1;
				int b=j/c2;
				int c=now[i][j]/c3;
				if(a>b)a=b;
				if(a>c)a=c;
			    if (d4>0) t+=a*d4;
				if(t>max) 
				{
					max=t;
				}
			}
		if(cas>1) printf("\n");
        printf("Case %d: %d\n",cas,max);
	}
	return 0;
}


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值