Advertisement
Alexandre_lsv

Untitled

Mar 24th, 2016
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.74 KB | None | 0 0
  1. #include <bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. ll mas[(ll)1e6] {};
  5. map<pair<ll,ll>,ll> countMap;
  6. int main()
  7. {
  8.     ll N;
  9.     cin >> N;
  10.     for(ll n=1; n<=N; n++){
  11.         for (ll rest=n; rest>0; rest--)
  12.             if (rest<n-rest)
  13.                 countMap[{n, n-rest}]=mas[rest];
  14.             else
  15.                 for(map<pair<ll,ll>,ll>::iterator it = countMap.lower_bound({rest, 1}); it!=countMap.upper_bound({rest, n-rest-1}); ++it)
  16.                     countMap[{n, n-rest}]+=(*it).second;
  17.         countMap[{n,n}]=1;
  18.         for (map<pair<ll,ll>,ll>::iterator it = countMap.lower_bound({n, 0}); it!=countMap.upper_bound({n,n}); ++it)
  19.             mas[n]+=(*it).second;
  20.     }
  21.     cout << endl << endl << N << "  :  " << mas[N] << endl << endl;
  22. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement