Advertisement
Alexandre_lsv

Untitled

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