#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;
}
ZOJ1013
最新推荐文章于 2021-03-27 04:55:12 发布