void CompletePacc(int cost,int weight)
{
int i;
for(i=cost;i<=v;i++)
if(dp[i]<dp[i-cost]+weight)
{
dp[i]=dp[i-cost]+weight;
}
}
void ZeroOnePacc(int cost,int weight)
{
int i;
for(i=v;i>=cost;i--)
if(dp[i]<dp[i-cost]+weight)
{
dp[i]=dp[i-cost]+weight;
}
}
void MultiPacc(int cost,int weight,int amount)
{
int k;
if( cost*amount > v )
{
CompletePacc(cost,weight);
return;
}
k=1;
while( k < amount )
{
ZeroOnePacc(k*cost,k*weight);
amount-=k;
k*=2;
}
ZeroOnePacc(amount*cost,amount*weight);
}