UVA_10664_Luggage

#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)
	{
		cin.get();
		while (T--)
		{	
			string str; getline(cin, str);
			stringstream stream; stream << str;
			vector<int>coin; int value;
			int sum = 0;
			while (stream>>value)
			{
				coin.push_back(value);
				sum += value;
			}
			if (sum % 2)
			{
				cout << "NO" << endl;
				continue;
			}
			vector<bool>dp(sum + 1);
			dp[0] = dp[sum] = true;
			for (int i = 0; i < coin.size(); i++)
			{
				for (int j = sum; j >= coin[i]; j--)
				{
					if (!dp[j])
					{
						dp[j] = dp[j - coin[i]];
					}
				}
			}
			if (dp[sum/2])
			{
				cout << "YES" << endl;
			}
			else
			{
				cout << "NO" << endl;
			}
		}
	}
	return 0;
}

你可能感兴趣的:(dynamic,programming,uva)