forked from daiwb/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path178.cpp
More file actions
40 lines (26 loc) · 728 Bytes
/
178.cpp
File metadata and controls
40 lines (26 loc) · 728 Bytes
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
#include <iostream>
using namespace std;
typedef long long LL;
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define MAXN 40
LL mm[MAXN + 5][10][2][2];
LL dp(int idx, int num, int n0, int n9) {
LL& ret = mm[idx][num][n0][n9];
if (ret != -1) return ret;
if (idx == MAXN) return ret = 0;
ret = 0;
if (n0 == 1 && n9 == 1) ++ret;
if (num >= 1) ret += dp(idx + 1, num - 1, num - 1 == 0 || n0, n9);
if (num <= 8) ret += dp(idx + 1, num + 1, n0, num + 1 == 9 || n9);
return ret;
}
int main() {
memset(mm, -1, sizeof(mm));
LL res = 0;
FOR(i,1,9) {
res += dp(0, i, 0, i == 9);
}
cout << res << endl;
return 0;
}