Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include<bits/stdc++.h>
- using namespace std;
- #define FOR(i,a,b) for(int i = (a); i < (b); i++)
- #define rep(i,n) FOR(i,0,n)
- #define RFOR(i,b,a) for(int i = (b) - 1; i>= (a); i--)
- #define ITER(it, a) for(typeof(a.begin()) it = a.begin(); it != a.end(); it++)
- #define FILL(a, value) memset(a, value, sizeof(a)
- #define SZ(a) (int)a.size()
- #define ALL(a) a.begin(), a.end()
- #define PB push_back
- #define MP make_pair
- typedef unsigned long long LL;
- typedef vector<int> VI;
- typedef vector<bool>VB;
- typedef pair<int, int> PII;
- const double PI = acos(-1.0);
- const int INF = 1000 * 1000 * 1000 + 7;
- const LL LINF = INF * (LL)INF;
- const double EPS = 1e-7;
- const int MAX = 20 * 1000 + 47;
- const int MOD = 1000 * 1000 * 1000 + 7;
- const int MAS = 1000 * 100;
- vector<int> add(VI & a, VI & b )
- {
- VI res = a;
- if (res.size() == 0)
- {
- res.push_back(0);
- }
- while(res.size() < b.size())
- {
- res.push_back(0);
- }
- while(b.size() < res.size())
- {
- b.push_back(0);
- }
- int nxt = 0 ;
- rep(i,res.size())
- {
- res[i] += b[i] + nxt;
- if (res[i] >= 10) {
- nxt = 1;
- res[i] -= 10;
- } else {
- nxt = 0;
- }
- }
- if (nxt == 1)
- {
- res.PB(nxt);
- }
- return res ;
- }
- vector<int> dp[1000][4];
- int main() {
- ios::sync_with_stdio(false);
- cin.tie(0);
- int n ;
- cin >> n;
- dp[0][1].PB(1);
- dp[1][2].PB(1);
- dp[2][3].PB(1) ;
- dp[2][2].PB(1) ;
- dp[2][1].PB(1);
- FOR(i,3,n )
- {
- dp[i][1] = add(dp[i-1][2],dp[i-1][3]) ;
- dp[i][2] =add(dp[i-2][1],dp[i-2][3]);
- dp[i][3] =add(dp[i-3][1],dp[i-3][2]);
- }
- VI res1 = add(dp[n-1][1],dp[n-1][2]);
- VI res2 = add(res1,dp[n-1][3]);
- for(auto it = res2.begin();it!=res2.end();it++ )
- cout<<*it;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement