如题= =自用模板

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
class Pack{  
int[]dp;
int M;
Pack(int vol){
dp=new int[vol+1];
M=vol;
}
void zeropack(int cost,int weight)
{
for(int i=M;i>=cost;i--)
dp[i]=Math.max(dp[i-cost]+weight,dp[i]);
}
void completepack(int cost,int weight)
{
for(int i=cost;i<=M;i++)
dp[i]=Math.max(dp[i-cost]+weight,dp[i]);
}
void multipack(int cost,int weight,int num)
{
if(num*cost>=M)
{
completepack(cost,weight);
return;
}
int k=1;
while(k<num)
{
zeropack(k*cost,k*weight);
num-=k;
k*=2;
}
zeropack(cost*num,weight*num);
}
}