1. 程式人生 > >HDU 2602: Bone Collector

HDU 2602: Bone Collector

sync cout include one == c++ tor lec nbsp

///@author Sycamore
///@date 9/11/2017
///@link http://acm.hdu.edu.cn/showproblem.php?pid=2602
#include <bits/stdc++.h>
using namespace std;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int T;
cin>>T;
while(T--)
{
int n,v;
cin>>n>>v;
vector<unsigned int>val(n),vol(n);
for(auto
&e:val)cin>>e;
for(auto &e:vol)cin>>e;
vector<vector<unsigned>>dp(n+1,vector<unsigned>(v+1));
for(unsigned i=0;i<=n;i++)
for(unsigned j=0;j<=v;j++)
{
if(i==0)dp[i][j]=0;//vol[i] may be ZERO
else if(vol[i-1]<=j)dp[i][j]=max(dp[i-1][j]
,dp[i-1][j-vol[i-1]]+val[i-1]);
else dp[i][j]=dp[i-1][j];
}

cout<<dp[n][v]<<\n;
}
return 0;
}

HDU 2602: Bone Collector