背包 Four Gate Push

Four Gate Push

Time Limit: 1 Sec   Memory Limit: 128 MB
Submit: 101   Solved: 59
[ Submit][ Status][ Web Board]

Description

You are working hard on your Protoss builds in StarCraft II, especially the 4 Gate Push. You've come upon
a tough problem, however, which is how to determine the distribution of zealots, stalkers, and sentries to
maximize your army strength. Recall (although you should already know!) that zealots cost 100 minerals
and no gas, stalkers cost 125 minerals and 50 gas, and sentries cost 50 minerals and 100 gas. Given your
current economy and how much each unit increases your army strength, determine the maximum army
strength you can obtain.

Input

The input consists of multiple test cases, one on each line. Each test case has 5 integers M (0 <= M <= 50;000),
the amount of minerals you have, G (0 <= G <= 50;000), the amount of gas you have, Z (0 <= Z <= 1;000),
the strength of a zealot in your army, S (0 <= S <= 1;000), the strength of a stalker in your army, and E
(0 <= E <= 1;000), the strength of a sentry in your army. Input is followed by a single line with M = G =
Z = S = E = 0, which should not be processed.

Output

For each case, output a single line containing the maximum army strength you can obtain.

Sample Input

500 400 10 20 15
0 0 0 0 0

Sample Output

95
我的2B做法:
View Code
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;
int g,m,a,b,c;

int dp[2010][1010];

int main()
{
//int d1[3][2]={{100,0},{125,50},{50,100}};
while(scanf("%d %d %d %d %d",&g,&m,&a,&b,&c)==5)
{
if(a+b+c+g+m==0) break;
memset(dp,0,sizeof(dp));
int Mg=g/25;
int Mm=m/50;
for(int i=1;i<=Mg;i++)
for(int j=1;j<=Mm;j++)
{
if(i>=4&&dp[i-4][j]+a>dp[i][j]) dp[i][j]=dp[i-4][j]+a;
if(i>=5&&dp[i-5][j-1]+b>dp[i][j]) dp[i][j]=dp[i-5][j-1]+b;
if(i>=2&&j>=2&&dp[i-2][j-2]+c>dp[i][j]) dp[i][j]=dp[i-2][j-2]+c;
}
printf("%d\n",dp[Mg][Mm]);
}
return 0;
}
大牛的做法:
View Code
#include<iostream> 
#include<cstdio>
using namespace std;
int main() {
int m, g, z, s, e;
int i, j, k;
int ans;
while (true) {
scanf("%d%d%d%d%d",&m,&g,&z,&s,&e);
if(!m && !g && !z && !e) break;
ans = 0;
for (i = 0; i*100<=m ; i++) {
for (j = 0 ; i*100+j*125<=m && j*50 <=g ; j++) {
k = min((m-i*100-j*125)/50,(g-j*50)/100);
ans = max(ans , i*z+j*s+k*e);
}
}
printf("%d\n",ans);
}
}



转载于:https://www.cnblogs.com/one--world--one--dream/archive/2012/03/31/2427300.html

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

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值