HDU_2602_Bone Collector

#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<list>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#pragma warning(disable:4996)
using std::cin;
using std::cout;
using std::endl;
using std::stringstream;
using std::string;
using std::vector;
using std::list;
using std::pair;
using std::set;
using std::multiset;
using std::map;
using std::multimap;
using std::stack;
using std::queue;
using std::priority_queue;
int main()
{
	//freopen("input.txt", "r", stdin);  
	//freopen("output.txt", "w", stdout);  
	int T;
	while(cin>>T)
	{
		while (T--)
		{
			int n, m; cin >> n >> m;
			vector<pair<int, int>>item(n);
			for (int i = 0; i < n; i++)
			{
				cin >> item[i].first;
			}
			for (int i = 0; i < n; i++)
			{
				cin >> item[i].second;
			}
			vector<int>dp(m + 1);
			for (int i = 0; i < n; i++)
			{
				for (int j = m; j >= item[i].second; j--)
				{
					dp[j] = std::max(dp[j - item[i].second] + item[i].first, dp[j]);
				}
			}
			cout << dp[m] << endl;
		}
	}
	return 0;
}

你可能感兴趣的:(HDU,knapsack)