#define max_n 101 #define max_m 100001 #define MAX(x,y) (x > y ? x : y) int c[max_n]; int w[max_n]; int n[max_n]; int f[max_m]; int V; void ZeroOnePack(int c,int w){ for(int v = V;v >= c;v--) f[v] = MAX(f[v],f[v - c] + w); } void CompletePack(int c,int w){ for(int v = c;v <= V;v++) f[v] = MAX(f[v],f[v - c] + w); } void MultiplePack(int c,int w,int n){ if(c * n >= V) CompletePack(c,w); int k = 1; while(k <= n){ ZeroOnePack(k * c,k * w); n -= k; k *= 2; } ZeroOnePack(n * c,n * w); }