Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)
Total Submission(s): 21463    Accepted Submission(s): 8633


Problem Description
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 ?
HDUOJ--Bone Collector
 

 

Input
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.
 

 

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

 

Sample Input
1 5 10 1 2 3 4 5 5 4 3 2 1
 

 

Sample Output
14
 

 

Author
Teddy
 

 

Source
 

 

Recommend
lcy

背包问题.....一定要多练习...

代码:----

 1 #include<stdio.h>
 2 #include<string.h>
 3 #define maxn 1005
 4 int dp[maxn],arr[maxn][2];
 5 int max(int a,int b)
 6 {
 7     return a>b?a:b;
 8 }
 9 
10 void zeroonepack(int cost ,int value,int v)
11 {
12      for(int i=v;i>=cost;i--)
13          dp[i]=max(dp[i],dp[i-cost]+value);
14 
15 }
16 int main()
17 {
18     int t,n,v ,i;
19     scanf("%d",&t);
20     while(t--)
21     {
22         scanf("%d%d",&n,&v);
23         memset(dp,0,sizeof dp);
24         for(i=0;i<n;i++)
25         {
26             scanf("%d",arr[i]+0);
27         }
28         for(i=0;i<n;i++)
29         {
30             scanf("%d",arr[i]+1);
31         }
32        for(i=0;i<n;i++)
33            zeroonepack(arr[i][1],arr[i][0],v);
34        printf("%d\n",dp[v]);
35     }
36     return 0;
37 }
View Code

相关文章:

  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-04-14
  • 2021-10-01
  • 2022-01-16
  • 2021-06-05
猜你喜欢
  • 2022-01-12
  • 2021-09-07
相关资源
相似解决方案