daily pastebin goal
11%
SHARE
TWEET

Untitled

a guest Jul 21st, 2018 104 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. const int MAXN = 101;
  6. const int MAXV = 1001;
  7.  
  8. int a[MAXN];
  9. bitset <MAXN * MAXV> dp;
  10.  
  11. void solve() {
  12.     int n;
  13.     cin >> n;
  14.     for (int i = 0; i < n; ++i) cin >> a[i];
  15.  
  16.     dp &= 0;
  17.     dp[0] = 1;
  18.     for (int i = 0; i < n; ++i) {
  19.         dp |= (dp << a[i]);
  20.     }                      
  21.  
  22.     int sum = 0;
  23.     for (int i = 0; i < n; ++i) sum += a[i];
  24.  
  25.     if (sum % 2 == 0 && dp[sum / 2]) {
  26.         cout << "YES\n";
  27.     }
  28.     else {
  29.         cout << "NO\n";
  30.     }  
  31. }
  32.  
  33. signed main() {
  34.     ios_base::sync_with_stdio(0);
  35.     cin.tie(0);
  36.  
  37.     int t;
  38.     cin >> t;
  39.     for (int i = 0; i < t; ++i) {
  40.         solve();
  41.     }
  42.  
  43.     return 0;
  44. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top