-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathThreeTiling.cpp
More file actions
71 lines (51 loc) · 1.09 KB
/
ThreeTiling.cpp
File metadata and controls
71 lines (51 loc) · 1.09 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
62
63
64
65
66
67
68
69
70
71
#include <iostream>
#include
using namespace std;
using ll = long long;
ll M = 1e9+7;
ll N = 1e6+5;
int main ()
{
ll t;
cin >> t;
ll dp[N];
ll dp2[N];
ll dp3[N];
dp[1] = 1;
dp2[1] = 0;
dp3[1] = 0;
dp[2] = 1;
dp2[2] = 0;
dp3[2] = 0;
dp[3] = 2;
dp2[3] = 0;
dp3[3] = 1;
for (ll i = 4; i < N; i++) {
dp[i] = (dp[i-3] + dp[i-1] + 2 * dp2[i-2]) % M;
dp2[i] = (dp3[i-1] + dp2[i-3]) % M;
dp3[i] = (dp[i-3] + dp3[i-3]) % M;
};
while (t--) {
ll k, n;
cin >> k >> n;
if (k == 1) {
if (n % 3 == 0) {
cout << 1 << endl;
} else {
cout << 0 << endl;
};
} else if (k == 2) {
ll DP[n];
DP[0] = 1;
DP[1] = 0;
DP[2] = 1;
DP[3] = 1;
for (ll i = 4; i <= n; ++i) {
DP[i] = (DP[i-2] + DP[i-3]) % M;
};
cout << DP[n] << endl;
} else if (k == 3) {
cout << dp[n] << endl;
}
}
}