Great Equipment - ZOJ 1013 dp

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


题意:有三种武器,每种武器有相应的重量,体积和威力,将三种武器按给定数量组合起来有更大的威力(我不确定是否比分开的要大,不过加上判定也不会错),然后你有n个背包,每个背包有限定的重量和体积,问最后获得的最大威力是多少。

思路:dp[i][j]表示在有i个第一种武器和j个第二种武器的时候,第三种武器最多有多少种,对于一个背包,枚举第一二中武器的情况后,对于前面的集合的情况,得到当前的情况,需要滚动数组。UVaLive 2422也是这道题,但是目前只有一个人过,我换成long long 类型的也不行,不知道为什么(其实这道题没给数据范围,应该用long long)。估计要么是UVa数据有坑,要么是ZOJ数据太弱。

AC代码如下:

#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
using namespace std;
int dp[2][510][510];
int num[5][5],box[110][2];
int n;
int main()
{ int t=0,i,j,k,a,b,len,w1,w2,num1,num2,num3,max1,max2,ret,ans;
  while(~scanf("%d",&n) && n>0)
  { memset(dp,-1,sizeof(dp));
    for(i=1;i<=3;i++)
     scanf("%d%d%d",&num[i][1],&num[i][2],&num[i][3]);
    scanf("%d%d%d%d",&num[4][1],&num[4][2],&num[4][3],&num[4][4]);
    dp[0][0][0]=0;
    for(i=1;i<=n;i++)
    { scanf("%d%d",&w1,&w2);
      if(i&1)
      {a=0;b=1;}
      else
      {a=1;b=0;}
      memset(dp[b],-1,sizeof(dp[b]));
      max1=min(w1/num[1][1],w2/num[1][2]);
      for(num1=max1;num1>=0;num1--)
      { max2=min((w1-num1*num[1][1])/num[2][1],(w2-num1*num[1][2])/num[2][2]);
        for(num2=max2;num2>=0;num2--)
        { num3=min((w1-num1*num[1][1]-num2*num[2][1])/num[3][1],(w2-num1*num[1][2]-num2*num[2][2])/num[3][2]);
          for(j=500;j>=num1;j--)
           for(k=500;k>=num2;k--)
            if(dp[a][j-num1][k-num2]>=0)
            dp[b][j][k]=max(dp[b][j][k],dp[a][j-num1][k-num2]+num3);
        }
      }
    }
    ans=0;
    for(num1=0;num1<=500;num1++)
     for(num2=0;num2<=500;num2++)
      if(dp[b][num1][num2]>=0)
      { num3=dp[b][num1][num2];
        ans=max(ans,num1*num[1][3]+num2*num[2][3]+num3*num[3][3]);
        k=min(num1/num[4][1],min(num2/num[4][2],num3/num[4][3]));
        ans=max(ans,(num1-k*num[4][1])*num[1][3]+(num2-k*num[4][2])*num[2][3]+(num3-k*num[4][3])*num[3][3]+k*num[4][4]);
      }
    if(t!=0)
     printf("\n");
    printf("Case %d: %d\n",++t,ans);
  }
}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值