ZOJ1013

#include <iostream>
#include <cstring>

#define CAVARAN_MAX 101
#define EACH_EQUIPMENT_MAX 501
#define MIN2(x, y) (x < y ? x : y)
#define MIN3(x, y, z) ((x < y ? x : y) < z ? (x < y ? x : y) : z)
#define MAX(x, y) (x < y ? y : x)
#define SWAP(x, y) {x ^= y; y ^= x; x ^= y;}

int bootNum[2][EACH_EQUIPMENT_MAX][EACH_EQUIPMENT_MAX];

int main()
{	
	int cavaranNum;
	int helm[3];//helm[0]: weight    helm[1]:size    helm[2]: defend capabilities
	int armor[3];//armor[0]: weight    armor[1]:size    armor[2]: defend capabilities
	int boot[3];//boot[0]: weight    boot[1]:size    boot[2]: defend capabilities
	int helmNumOneSet;
	int armorNumOneSet;
	int bootNumOneSet;
	int capabilitiesOneSet;
	int cavaranLimit[CAVARAN_MAX][2];//cavaran[...][0]: weight limit    cavaran[...][1]: size limit
	int pre;
	int now;
	int helmTmp;
	int armorTmp;
	int maxCapabilities;
	int caseNum = 1;
	while(std:: cin >> cavaranNum)
	{
		if(0 == cavaranNum)
		{
			break;
		}
		std:: cin >> helm[0] >> helm[1] >> helm[2];
		std:: cin >> armor[0] >> armor[1] >> armor[2];
		std:: cin >> boot[0] >> boot[1] >> boot[2];
		std:: cin >> helmNumOneSet >> armorNumOneSet >> bootNumOneSet >> capabilitiesOneSet;
		for(int i = 0; i < cavaranNum; ++i)
		{
			std:: cin >> cavaranLimit[i][0] >> cavaranLimit[i][1];
		}
		pre = 0;
		now = 1;
		helmTmp = armorTmp = 0;
		memset(bootNum, 0, sizeof(bootNum));
		for(int i = 0; i < cavaranNum; ++i)
		{
			memset(bootNum[now], -1, sizeof(bootNum[now]));
			int helmMax = MIN2(cavaranLimit[i][0] / helm[0], cavaranLimit[i][1] / helm[1]);
			for(int j = 0; j <= helmMax; ++j)//helm
			{
				int armorMax = MIN2((cavaranLimit[i][0] - j * helm[0]) / armor[0], 
					(cavaranLimit[i][1] - j * helm[1]) / armor[1]);
				for(int k = 0; k <= armorMax; ++k)//armor
				{
					int bootMax = MIN2((cavaranLimit[i][0] - j * helm[0] - k * armor[0]) / boot[0], 
						(cavaranLimit[i][1] - j * helm[1] - k * armor[1]) / boot[1]);
					for(int m = 0; m <= helmTmp; ++m)
					{
						for(int n = 0; n <= armorTmp; ++n)
						{
							if(bootNum[pre][m][n] != -1)
							{
								bootNum[now][m + j][n + k] = MAX(bootNum[now][m + j][n + k], 
									bootNum[pre][m][n] + bootMax);
							}
							//if(bootNum[pre][m][n] != -1 &&
							//	bootNum[now][m + j][n + k] < bootNum[pre][m][n] + bootMax)
							//{
							//	bootNum[now][m + j][n + k] = bootNum[pre][m][n] + bootMax;
							//}
						}
					}
				}
			}
			helmTmp += helmMax;
			armorTmp += MIN2(cavaranLimit[i][0] / armor[0], cavaranLimit[i][1] / armor[1]);
			SWAP(pre, now);
		}
		maxCapabilities = 0;
		for(int i = 0; i <= helmTmp; ++i)
		{
			for(int j = 0; j <= armorTmp; ++j)
			{
				if(bootNum[pre][i][j] < 0)
				{
					continue;
				}
				int maxSetNum = MIN3(i / helmNumOneSet, j / armorNumOneSet, 
					bootNum[pre][i][j] / bootNumOneSet);
				maxCapabilities = MAX(maxCapabilities, maxSetNum * capabilitiesOneSet + 
					(i - maxSetNum * helmNumOneSet) * helm[2] + 
					(j - maxSetNum * armorNumOneSet) * armor[2] + 
					(bootNum[pre][i][j] - maxSetNum * bootNumOneSet) * boot[2]);
			}
		}
		//std:: cout << "Case " << caseNum++ << ": " << maxCapabilities << std:: endl << std:: endl;
		if(caseNum > 1) std:: cout << std:: endl;
		std:: cout << "Case " << caseNum++ << ": " << maxCapabilities << std:: endl;
	}
	return 0;
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值