Advertisement
Bohdan_Chaika

Untitled

Mar 20th, 2019
468
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.85 KB | None | 0 0
  1. #include<bits/stdc++.h>
  2. using namespace std;
  3.  
  4. #define FOR(i,a,b) for(int i = (a); i < (b); i++)
  5.  
  6. #define rep(i,n) FOR(i,0,n)
  7. #define RFOR(i,b,a) for(int i = (b) - 1; i>= (a); i--)
  8. #define ITER(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
  9. #define FILL(a, value) memset(a, value, sizeof(a)
  10.  
  11. #define SZ(a) (int)a.size()
  12. #define ALL(a) a.begin(), a.end()
  13. #define PB push_back
  14. #define MP make_pair
  15.  
  16. typedef unsigned long long LL;
  17. typedef vector<int> VI;
  18. typedef vector<bool>VB;
  19. typedef pair<int, int> PII;
  20.  
  21. const double PI = acos(-1.0);
  22. const int INF = 1000 * 1000 * 1000 + 7;
  23. const LL LINF = INF * (LL)INF;
  24.  
  25. const double EPS = 1e-7;
  26. const int MAX = 20 * 1000 + 47;
  27. const int MOD = 1000 * 1000 * 1000 + 7;
  28. const int MAS = 1000 * 100;
  29.  
  30. vector<int> add(VI & a, VI & b )
  31. {
  32. VI res = a;
  33. if (res.size() == 0)
  34. {
  35. res.push_back(0);
  36. }
  37. while(res.size() < b.size())
  38. {
  39. res.push_back(0);
  40. }
  41. while(b.size() < res.size())
  42. {
  43. b.push_back(0);
  44. }
  45. int nxt = 0 ;
  46. rep(i,res.size())
  47. {
  48. res[i] += b[i] + nxt;
  49.  
  50. if (res[i] >= 10) {
  51. nxt = 1;
  52. res[i] -= 10;
  53. } else {
  54. nxt = 0;
  55. }
  56.  
  57.  
  58. }
  59. if (nxt == 1)
  60. {
  61. res.PB(nxt);
  62. }
  63. return res ;
  64.  
  65.  
  66. }
  67.  
  68. vector<int> dp[1000][4];
  69. int main() {
  70. ios::sync_with_stdio(false);
  71. cin.tie(0);
  72. int n ;
  73. cin >> n;
  74. dp[0][1].PB(1);
  75. dp[1][2].PB(1);
  76. dp[2][3].PB(1) ;
  77. dp[2][2].PB(1) ;
  78. dp[2][1].PB(1);
  79. FOR(i,3,n )
  80. {
  81. dp[i][1] = add(dp[i-1][2],dp[i-1][3]) ;
  82. dp[i][2] =add(dp[i-2][1],dp[i-2][3]);
  83. dp[i][3] =add(dp[i-3][1],dp[i-3][2]);
  84.  
  85. }
  86. VI res1 = add(dp[n-1][1],dp[n-1][2]);
  87. VI res2 = add(res1,dp[n-1][3]);
  88. for(auto it = res2.begin();it!=res2.end();it++ )
  89. cout<<*it;
  90.  
  91. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement