Advertisement
tien_noob

Two Sets II ( CSES )

Feb 18th, 2021
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.67 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4. #include <numeric>
  5. #include <cmath>
  6. #include <queue>
  7. using namespace std;
  8. const int N = 500*501/4, mod = 1e9 + 7;
  9. long long n, dp[N+1], m;
  10. void read()
  11. {
  12.    cin >> n;
  13. }
  14. void solve()
  15. {
  16.    if (n * (n+1) % 4 != 0)
  17.    {
  18.        cout << 0; return ;
  19.    }
  20.    fill(dp + 1, dp + N + 1, 0);
  21.    m = n * (n + 1)/4;
  22.    dp[0] = 1;
  23.    for (int i = 1; i <= n; ++ i)
  24.    {
  25.        for (int j = m; j >= i; -- j)
  26.        {
  27.            dp[j] = (dp[j] + dp[j - i]) % mod;
  28.        }
  29.    }
  30.    cout << (dp[m] * (mod + 1)/2) % mod; // Nghich dao modulo
  31. }
  32. int main()
  33. {
  34.     ios_base::sync_with_stdio(false);
  35.     cin.tie(nullptr);
  36.     read();
  37.     solve();
  38. }
  39.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement