input:treasure.in output:treasure.out
时间限制: 1000 ms 空间限制: 60000 KB 具体限制
1 #include<bits/stdc++.h> 2 using namespace std; 3 int v[4*10005],w[4*10005]; 4 int f[4*10005]; 5 int n,m,nl; 6 int main() 7 { 8 freopen("treasure.in","r",stdin); 9 freopen("treasure.out","w",stdout); 10 cin>>n>>m; 11 for(int i=1;i<=n;i++) 12 { 13 int x,y,s,t=1; 14 cin>>y>>x>>s; 15 while(s>=t) 16 { 17 v[++nl]=x*t; 18 w[nl]=y*t; 19 s-=t; 20 t*=2; 21 } 22 v[++nl]=x*s; 23 w[nl]=y*s; 24 } 25 for(int i=1;i<=nl;i++) 26 for(int j=m;j>=v[i];j--) 27 f[j]=max(f[j],f[j-v[i]]+w[i]); 28 cout<<f[m]; 29 }