Bone Collector
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 26423 Accepted Submission(s): 10700
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 ?
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.
1 5 10 1 2 3 4 5 5 4 3 2 1
14
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
int T,N,V;
cin>>T;
while(T--)
{
cin>>N>>V;
int Val[1001];int Vol[1001];int F[1001];
for(int i=1;i<=N;i++)
{
cin>>Val[i];
}
for(int i=1;i<=N;i++)
{
cin>>Vol[i];
}
for(int i=0;i<=V;i++)
{
F[i]=0;
}
for(int i=1;i<=N;i++)
{
for(int v=V;v>=Vol[i];v--)
F[v]=max(F[v],F[v-Vol[i]]+Val[i]);
}
cout<<F[V]<<endl;
}
return 0;
}
552



被折叠的 条评论
为什么被折叠?



