Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- bool subsetsum(int arr[],int n,int s)
- {
- int i,j;
- bool a[n+1][s+1];
- for(i=0;i<=n;i++)
- {
- for(j=0;j<=s;j++)
- {
- if(j==0)a[i][j]=true;
- else{
- if(i==0)a[i][j]=false;
- else{
- if(arr[i-1]>j)a[i][j]=a[i-1][j];
- else{
- a[i][j]=a[i-1][j]||a[i-1][j-arr[i-1]];
- }
- }
- }
- }
- }
- return a[n][s];
- }
- int main()
- {
- int i,j,t,m,n;
- cin>>t;
- while(t--)
- {
- int s=0;
- cin>>n;
- int a[n];
- for(i=0;i<n;i++){cin>>a[i]; s+=a[i];}
- if(s%2==1){cout<<"NO\n"; continue;}
- s/=2;
- if(subsetsum(a,n,s))cout<<"YES\n";
- else cout<<"NO\n";
- }
- }
Add Comment
Please, Sign In to add comment