背包 Four Gate Push
Four Gate Push
Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 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
Sample Output
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#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;
}
![](https://images.cnblogs.com/OutliningIndicators/ContractedBlock.gif)
#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);
}
}