-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path1562.cpp
More file actions
55 lines (38 loc) · 1.17 KB
/
1562.cpp
File metadata and controls
55 lines (38 loc) · 1.17 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
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<cstring>
#include <string>
using namespace std;
int N;
int dp[101][10][1 << 10];
int modul = 1000000000;
int stair(int leng, int num, int visited) {
if (leng == 1) {
if (visited == 1023) {
return 1;
}
return 0;
}
if (dp[leng][num][visited] != -1)
return dp[leng][num][visited];
if (num == 0)
return dp[leng][num][visited] = stair(leng - 1, 1, visited | (1 << (num + 1))) % modul;
if (num == 9)
return dp[leng][num][visited] = stair(leng - 1, 8, visited | (1 << (num - 1))) % modul;
return dp[leng][num][visited] =
(stair(leng - 1, num - 1, visited | (1 << (num - 1))) % modul +
stair(leng - 1, num + 1, visited | (1 << (num + 1))) % modul) % modul;
}
int main() {
ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
memset(dp, -1, sizeof(dp));
cin >> N;
int visited = 0;
int val = 0;
for (int i = 1; i <= 9; i++) {
val = (val % modul + stair(N, i, 1 << i) % modul) % modul;
}
cout << val;
}