fork download
  1. #include <bits/stdc++.h>
  2. #define ll long long
  3.  
  4. using namespace std;
  5.  
  6. const int MOD = 1e9 + 7;
  7. vector<ll> ans(87, 0);
  8.  
  9. vector<vector<vector<ll>>> dp(90, vector<vector<ll>>(2, vector<ll>(87, -1)));
  10.  
  11. bool solve(){
  12. int x;
  13. cin >> x;
  14. if(x == 0)return false;
  15. cout << ans[x] << "\n";
  16. return true;
  17.  
  18. }
  19.  
  20. void dfs(int x, int branched){
  21. if(x > 85){
  22. dp[x][branched].assign(87, 0);
  23. return;
  24. }
  25. if(dp[x][branched][0] != -1){
  26. for(int i = 2; i <= 85; i++)ans[i] += (dp[x][branched][i]);
  27. return;
  28. }
  29.  
  30. dp[x][branched].assign(87, 0);
  31. dp[x][branched][x]++;
  32. ans[x]++;
  33. if(branched){
  34.  
  35. dfs(x + 1, 1);
  36. dfs(x + 1, 0);
  37. for(int i = x + 1; i <= 85; i++)dp[x][branched][i] += (dp[x + 1][1][i] + dp[x + 1][0][i]);
  38.  
  39. }else{
  40. dfs(x + 1, 1);
  41. for(int i = x + 1; i <= 85; i++)dp[x][branched][i] += (dp[x + 1][1][i]);
  42.  
  43. }
  44.  
  45.  
  46.  
  47. }
  48.  
  49. int main(){
  50. ios_base::sync_with_stdio(false);
  51. cin.tie(nullptr);
  52.  
  53. ans[1] = 1;
  54.  
  55.  
  56. dfs(2, 1);
  57. int t = 1;
  58. // cin >> t;
  59. // cout << ans[] << "\n";
  60. // return 0;
  61.  
  62. for(; solve();){
  63. }
  64. return 0;
  65. }
Success #stdin #stdout 0.01s 5276KB
stdin
2
3
4
5
6
7
8
9
85
0
stdout
1
2
3
5
8
13
21
34
259695496911122585