void MultiplePack(int C,int W,int M)
{
    if(C*M>=V)
        return CompletePack(C,W);
    int k=1;
    while(k<M)
    {
        ZeroOnePack(k*C,k*W);
        M=M-k;
        k=k+k;
    }
    if(M!=0)
        ZeroOnePack(M*C,M*W);
}
Example #2
0
void
MultiplePack(int cost, int value, int amount)
{
	int k = 1;
	if(cost*amount >= vol)
		CompletePack(cost, value);
	else {
		while((amount-k) >= 0) {  
			ZeroOnePack(cost*k, value*k);
			amount -= k;
			k = k*2;
		}
		ZeroOnePack(cost*amount, value*amount);
	}
}
Example #3
0
void MultiplePack(int cost,int weight,int amount)//多重背包
{
       int k;
       if (cost*amount>=V)
       {
        CompletePack(cost,weight);
              return;
       }
       k=1;
       while(k<amount)
       {
              ZeroOnePack(k*cost,k*weight);
              amount=amount-k;
              k=k*2;//分割
       }
       ZeroOnePack(amount*cost,amount*weight);
}