混合背包
Time Limit:10000MS Memory Limit:65536K
Total Submit:146 Accepted:88
Case Time Limit:1000MS
Description
背包体积为V ,给出N个物品,每个物品占用体积为Vi,价值为Wi,每个物品要么至多取1件,要么至多取mi件(mi > 1) , 要么数量无限 , 在所装物品总体积不超过V的前提下所装物品的价值的和的最大值是多少?
Input
第一行两个数V,N下面N行每行三个数Vi,Wi,Mi表示每个物品的体积,价值与数量,Mi=1表示至多取一件,Mi>1表示至多取Mi件,Mi=0表示数量无限
Output
1个数Ans表示所装物品价值的最大值
Sample Input
10 3
2 1 0
3 3 1
4 5 4
Sample Output
11
-
var n,m,i,j,k,l:longint; w,c,p:array[0..30] of longint; f:array[0..200] of longint; begin readln(n,m); for i:=1 to m do readln(w[i],c[i],p[i]); for i:=1 to m do if p[i]=0 then begin for j:=w[i] to n do if f[j-w[i]]+c[i]>f[j] then f[j]:=f[j-w[i]]+c[i]; end else begin for j:=1 to p[i] do for k:=n downto w[i] do if f[k-w[i]]+c[i]>f[k] then f[k]:=f[k-w[i]]+c[i]; end; writeln(f[n]); end.