64,648
社区成员
发帖
与我相关
我的任务
分享
void ZeroOnePack (int cost, int weight)
{
int v;
for (v = n; v >= cost; v--)
fmax[v] = fmax[v] > (fmax[v - cost] + weight) ? fmax[v] : (fmax[v - cost] + weight);
}
void CompletePack (int cost, int weight)
{
int v;
for (v = cost; v <= n; v++)
fmax[v] = fmax[v] > (fmax[v - cost] + weight) ? fmax[v] : (fmax[v - cost] + weight);
}
void MultiplePack(int cost, int weight, int amount)
{
if (cost * amount >= n)
CompletePack (cost, weight);
int k = 1;
while (k < amount)
{
ZeroOnePack (k * cost, k * weight);
amount = amount - k;
k = k * 2;
}
ZeroOnePack (amount * cost, amount * weight);
}