forked from Saiyamjain-100/coder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdp3.cpp
65 lines (60 loc) · 1.03 KB
/
dp3.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
53
54
55
56
57
58
59
60
61
62
63
64
65
#include<iostream>
#include<vector>
using namespace std;
#include<bits/stdc++.h>
#include<string>
#include<vector>
#include <set>
#define lli long long int
#define ull unsigned long long int
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define mods 1000000007
knapsack(lli a[] , int n, int sum){
bool t[n+1][sum+1];
for(int i=0;i<n+1;i++){
t[i][0]==true;
}
for(int i=1;i<sum+1;i++){
t[0][i]==false;
}
for(int i=1;i<n+1;i++){
for(int j=1;j<sum+1;j++){
if(a[i-1]<=j){
t[i][j]=(t[i-1][j-a[i-1]] || t[i-1][j]);
}
else{
t[i][j]=t[i-1][j];
}
}
}
return (t[n][sum]);
}
int main(){
#ifndef ONLINE_JUDGE
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
#endif
int t=1;
cin>>t;
while(t--){
int n,sum=0;
cin>>n ;
lli arr[n];
for(int i=0;i<n;i++){
cin>>arr[i];
sum=sum+arr[i];
}
if(sum%2!=0){
cout<<"false"<<"\n";
}
else{
int p=sum/2;
if(knapsack(arr ,n , p)==true){
cout<<"YEs";
}
else{
cout<<"NO";
}
}
}
}