Bone Collector

来源:互联网 发布:wav音乐分割软件 编辑:程序博客网 时间:2024/06/05 08:42

题目描述

 Many years ago , in Teddy’s hometown there was a man who was called “Bone Collector”. This man like to collect varies of bones , such as dog’s , cow’s , also he went to the grave …
The bone collector had a big bag with a volume of V ,and along his trip of collecting there are a lot of bones , obviously , different bone has different value and different volume, now given the each bone’s value along his trip , can you calculate out the maximum of the total value the bone collector can get ?
 

输入

 The first line contain a integer T , the number of cases.
Followed by T cases , each case three lines , the first line contain two integer N , V, (N <= 1000 , V <= 1000 )representing the number of bones and the volume of his bag. And the second line contain N integers representing the value of each bone. The third line contain N integers representing the volume of each bone.

输出

 One integer per line representing the maximum of the total value (this number will be less than 231).
 

示例输入

15 101 2 3 4 55 4 3 2 1

示例输出

14
 
  1. #include <bits/stdc++.h>  
  2. using namespace std;  
  3. int main()  
  4. {  
  5.     int dp[1002];  
  6.     int w[1002],v[1002];  
  7.     int i,j,k,l,T,n,m;  
  8.     cin>>T;  
  9.     while(T--)  
  10.     {  
  11.         cin>>n>>m;  
  12.         for(i=1;i<=n;i++)  
  13.         {  
  14.             cin>>w[i];  
  15.         }  
  16.         for(i=1;i<=n;i++)  
  17.            {  
  18.                cin>>v[i];  
  19.            }  
  20.            memset(dp,0,sizeof(dp));  
  21.         for(i=1;i<=n;i++)  
  22.         {  
  23.             for(j=m;j>=v[i];j--)  
  24.             {  
  25.                 dp[j]=max(dp[j],dp[j-v[i]]+w[i]);  
  26.             }  
  27.         }  
  28.         cout<<dp[m]<<endl;  
  29.     }  
  30. }   
  31.   
0 0
原创粉丝点击