hdu2602 Bone Collector

 1 #include<iostream>

 2 using namespace std;

 3 int f[1001][1001],w[1001],v[1001];

 4 int main()

 5 {

 6     int i,j,n,totalv,T;

 7     cin>>T;

 8     while(T--){

 9         cin>>n>>totalv;

10         for(i=1;i<=n;++i)

11             cin>>v[i];

12         for(i=1;i<=n;++i)

13             cin>>w[i];

14         for(i=1;i<=n;++i)

15             for(j=0;j<=totalv;++j)

16                     f[i][j]=max(f[i-1][j],w[i]>j?f[i-1][j]:v[i]+f[i-1][j-w[i]]);

17         cout<<f[n][totalv]<<endl;

18     }

19     return 0;

20 }

你可能感兴趣的:(Collector)