-
Notifications
You must be signed in to change notification settings - Fork 0
/
2718.cpp
60 lines (51 loc) · 1.1 KB
/
2718.cpp
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
#include <iostream>
#include <algorithm>
#include <cstring>
#define N 1000000
using namespace std;
int n, d[N][5];
int dp(int index, int state)
{
if (index == 0 && state == 0)
return 1;
if (index == 0 && state)
return 0;
if (index < 0)
return 0;
if (d[index][state] != -1)
return d[index][state];
int val;
switch (state)
{
case 0:
val = dp(index - 1, 0) + dp(index - 1, 1) + dp(index - 1, 2) + dp(index - 1, 3) + dp(index - 2, 0);
break;
case 1:
val = dp(index - 1, 0) + dp(index - 1, 2);
break;
case 2:
val = dp(index - 1, 0) + dp(index - 1, 1);
break;
case 3:
val = dp(index - 1, 0) + dp(index - 1, 4);
break;
case 4:
val = dp(index - 1, 3);
break;
}
return d[index][state] = val;
}
int main()
{
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
int t, tc, i;
cin >> tc;
memset(d, -1, sizeof(d));
for (t = 0; t < tc; t++)
{
cin >> n;
cout << dp(n, 0) << endl;
}
return 0;
}