Alex_tz307

Fundamente XI - 2 / 218

Sep 21st, 2020 (edited)
100
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.63 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2.  
  3. using namespace std;
  4.  
  5. int main() {
  6.     ios_base::sync_with_stdio(false);
  7.     cin.tie(nullptr);
  8.     cout.tie(nullptr);
  9.     int N;
  10.     cin >> N;
  11.     vector < int > a(N);
  12.     int sum = 0;
  13.     for(int& x : a) {
  14.         cin >> x;
  15.         sum += x;
  16.     }
  17.     vector < bool > dp(32768);
  18.     int ans = 0;
  19.     for(int x : a) {
  20.         for(int i = sum; i >= 0; --i)
  21.             if(dp[i]) {
  22.                 if(!dp[i + x])
  23.                     ++ans;
  24.                 dp[i + x] = true;
  25.             }
  26.         if(!dp[x]) {
  27.             ++ans;
  28.             dp[x] = true;
  29.         }
  30.     }
  31.     cout << ans;
  32. }
  33.  
Add Comment
Please, Sign In to add comment