-
Notifications
You must be signed in to change notification settings - Fork 0
/
Luggage.cpp
52 lines (49 loc) · 870 Bytes
/
Luggage.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
#include<bits/stdc++.h>
using namespace std;
int dp[20][200],a[20],sum,n;
int knap(int i,int w)
{
if(i==n)
{
if(w==0)
return 1;
else
return 0;
}
if(dp[i][w]!=-1)
return dp[i][w];
int pos1=0,pos2=0;
if(w-a[i]>=0)
pos1=knap(i+1,w-a[i]);
pos2=knap(i+1,w);
return dp[i][w]=pos1|pos2;
}
main()
{
int t,i,j,num;
cin>>t;
getchar();
string s;
for(i=0;i<t;i++)
{
n=sum=0;
// getchar();
getline(cin,s);
stringstream ss;
ss<<s;
while(ss>>a[n])
{
sum+=a[n];
n++;
}
ss.clear();
if(sum%2==0)
{
sum>>=1;
memset(dp,-1,sizeof(dp));
cout<<(knap(0,sum)?"YES\n":"NO\n");
}
else
cout<<"NO\n";
}
}