void CompletePack(int cost,int weight) 多重背包
{
for(int i=cost;i<=m;i++)
dp[i]=max(dp[i],dp[i-cost]+weight);
}
void ZeroOnePack(int cost,int weight) 01背包
{
for(int i=m;i>=cost;i--)
dp[i]=max(dp[i],dp[i-cost]+weight);
}
void MultiplyPack(int cost,int weight,int amount) 完全背包
{
if(cost*amount>=m)
CompletePack(cost,weight);
else
{
int k=1;
while(k<amount)
{
ZeroOnePack(k*cost,k*weight);
amount-=k;
k<<=1;
}
ZeroOnePack(amount*cost,amount*weight);
}
}
详情看
HDU 2844 Coins (动规)
多重背包转换成完全背包和01背包,布布扣,bubuko.com
多重背包转换成完全背包和01背包
原文:http://blog.csdn.net/qq2256420822/article/details/38024611