-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWhiteSpaceDp.cpp
More file actions
61 lines (53 loc) · 1.04 KB
/
WhiteSpaceDp.cpp
File metadata and controls
61 lines (53 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <fstream>
#define F first
#define S second
#define PG push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <= b; i++)
#define N 100003
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
int dp[N][2][2][2];
int mod = 1000000007;
int f(int n, int t, int r, int s){
if(n < 0) return 0;
if(n==0){
return !(t|r|s);
}
if(dp[n][t][r][s] != -1) return dp[n][t][r][s];
int res = 0;
if(t != 0){
res = ((res + f(n-1,1,r,s))%mod) + f(n-1,0,r,s) % mod;
}
if(r != 0){
res = ((res + f(n-2,t,1,s)) % mod) + f(n-2,t,0,s) % mod;
}
if(s != 0){
res = ((res + f(n-3,t,r,1))%mod) + f(n-3,t,r,0) % mod;
}
dp[n][t][r][s] = res;
return res;
}
int main(){
ios::sync_with_stdio(0);
cin.tie(0);
for(int i = 0; i < N; i++){
for(int j = 0; j < 2; j++){
for(int k = 0; k< 2; k++){
for(int l = 0; l < 2; l++){
dp[i][j][k][l] = -1;
}
}
}
}
int n;
cin >> n;
cout<<f(n,1,1,1)<<endl;
return 0;
}