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