01背包,完全背包,多重背包 ,模板代码

01 背包

 

void bag01(int cost,int weight)
{
 for(i=v;i>=cost;i--)
  if(dp[i]


完全背包

 

void complete(int cost,int weight)
{
 for(i=cost;i<=v;i++)
  if(dp[i]


 

多重背包

 

void multiply(int cost,int weight,int amount)
{
 if(cost*amount>=v)
  complete(cost,weight);
 else{
  k=1;
  while(k


 

你可能感兴趣的:(五,多重背包问题,一,0/1背包问题,ACM算法之美)