forked from daiwb/Algorithm
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path145.cpp
More file actions
72 lines (61 loc) · 1.17 KB
/
145.cpp
File metadata and controls
72 lines (61 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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#include <iostream>
#include <sstream>
#include <algorithm>
#include <iterator>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <cmath>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
typedef long long LL;
#define MAXN 9
LL mm[10][2][2];
LL dp(int len, int a, int b) {
LL& ret = mm[len][a][b];
if (ret != -1) return ret;
if (len == 1) {
if (a == 0) return ret = 0;
ret = 0;
FOR(i,0,9) {
int t = (i + i + a);
if (t / 10 != b) continue;
++ret;
}
return ret;
}
if (len == 0) {
if (a == b) return ret = 1;
else return ret = 0;
}
ret = 0;
FOR(i,0,9) {
FOR(j,0,9) {
int l = (i + j + a);
if ((l & 1) == 0) continue;
int r = (i + j);
if (r / 10 != b) continue;
ret += dp(len - 2, l / 10, 1 - r & 1);
}
}
return ret;
}
void run() {
memset(mm, -1, sizeof(mm));
LL res = 0;
FOR(len,2,MAXN) {
FOR(i,1,9) {
FOR(j,1,9) {
if (((i + j) & 1) == 0) continue;
res += dp(len - 2, (i + j) / 10, 1 - (i + j) & 1);
}
}
}
cout << res << endl;
}
int main () {
run();
return 0;
}