-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathmain.cpp
More file actions
59 lines (56 loc) · 1.36 KB
/
Copy pathmain.cpp
File metadata and controls
59 lines (56 loc) · 1.36 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
#include <bits/stdc++.h>
using namespace std;
constexpr int mod = 1'000'000'007;
auto sol = [](int n, int m) {
auto conv = [](string s) {
string c(6, 0);
char p = '1';
for (int i = 0; i < s.size(); i++) {
if (s[i] < '2') continue;
if (c[s[i] - '0'] == 0) c[s[i] - '0'] = ++p;
s[i] = c[s[i] - '0'];
}
return s;
};
map dp{ pair(string(n - 1, '0') + "1", 1) };
for (int iter = 0; iter < m; iter++) {
for (int i = 0; i < n; i++) {
if (iter == 0 && i == 0) continue;
map ndp{ pair(string(0, 0), 0) };
ndp.clear();
auto update = [&](string s, int val) {
s = conv(s);
if (s.find('1') == -1) return;
ndp[s] += val;
if (ndp[s] >= mod) ndp[s] -= mod;
};
for (auto [s, val] : dp) {
string ns = s.substr(1);
ns.push_back('0');
update(ns, val);
ns.pop_back();
char v1 = '5';
char v2 = '5';
if (s[0] != '0') v1 = s[0];
if (i > 0 && s[n - 1] != '0') v2 = s[n - 1];
if (v1 > v2) swap(v1, v2);
for (char& c : ns) if (c == v2) c = v1;
ns.push_back(v1);
update(ns, val);
}
dp.swap(ndp);
}
}
int ret = 0;
for (auto [s, val] : dp) {
if (s[n - 1] != '1') continue;
ret += val;
if (ret >= mod) ret -= mod;
}
return ret;
};
int main() {
cin.tie(0)->sync_with_stdio(0);
int n, m; cin >> n >> m;
cout << sol(n, m) << '\n';
}