fork download
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. #define endl "\n"
  4. #define ll long long
  5. #define faster() ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
  6. const int MOD = 1e9 + 7 ;
  7.  
  8. int a[105], dp[105] , n , total;
  9.  
  10. void solve(){
  11. total = 0 ;
  12. cin >> n ;
  13. for(int i = 1 ; i <= n ; i++){
  14. cin >> a[i];
  15. total += a[i];
  16. }
  17. if(total % 2 != 0) cout << "0" << endl ;
  18. else{
  19. total /= 2 ;
  20. dp[0] = 1 ;
  21. for(int i = 1 ; i <= total ; i++){
  22. for(int j = 1 ; j <= n ; j++){
  23. if(i - a[j] >= 0 && dp[i - a[j]]){
  24. dp[i] = 1;
  25. }
  26. }
  27. }
  28. cout << dp[total] ;
  29. }
  30. }
  31.  
  32.  
  33. int main() {
  34. faster();
  35. int test = 1 ;
  36. // cin >> test ;
  37. while(test--) solve();
  38. return 0;
  39. }
  40.  
  41.  
  42.  
Success #stdin #stdout 0.01s 5276KB
stdin
Standard input is empty
stdout
1