TOJ 3479 Four Gate Push /完全背包

Four Gate Push

时间限制(普通/Java):1000MS/3000MS     运行内存限制:65536KByte

描述

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.

输入

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.

输出

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

样例输入

500 400 10 20 15
0 0 0 0 0

样例输出

95

等价于有2个背包体积的完全背包 不过 那个 i的循环放最外面这么就错了 ??? 求解
#include <stdio.h>
#include <string>
#define MAX 2010
int dp[MAX][MAX];
main()
{
	int map[4][2] = {{4,0},{5,1},{2,2}};
	int i,j,k,m,g;
	int a[3];
	while(scanf("%d %d %d %d %d",&m,&g,&a[0],&a[1],&a[2]),m||g||a[0]||a[1]||a[2])
	{
		memset(dp,0,sizeof(dp));
		m /= 25;
		g /= 50;
		for(j = 1; j <= m; j++)
		{
			for(k = 1; k <= g; k++)
			{
				for(i = 0;i < 3; i++)
				{
					if(j >= map[i][0] && k >= map[i][1])
					{
						if(dp[j][k] < dp[j-map[i][0]][k-map[i][1]] + a[i])
						{
							dp[j][k] = dp[j-map[i][0]][k-map[i][1]] + a[i];
						}
					}
				}
			}
		}
		printf("%d\n",dp[m][g]);
	}
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值