-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray_description.cpp
More file actions
57 lines (48 loc) · 1.04 KB
/
Copy patharray_description.cpp
File metadata and controls
57 lines (48 loc) · 1.04 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
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define endl '\n'
#define sz(x) (int)(x).size()
#define all(x) begin(x), end(x)
#define MOD 1000000007
int main() {
ios_base::sync_with_stdio(false);
cin.tie(nullptr);
int n, m;
cin >> n >> m;
vector<int> a(n);
for (int i = 0; i < n; ++i) {
cin >> a[i];
}
vector<vector<int>> dp(n, vector<int>(m + 1, 0));
if (a[0] == 0) {
for (int x = 1; x <= m; ++x) {
dp[0][x] = 1;
}
} else {
dp[0][a[0]] = 1;
}
for (int i = 1; i < n; ++i) {
if (a[i] == 0) {
for (int x = 1; x <= m; ++x) {
for (int k : {x - 1, x, x + 1}) {
if (k >= 1 && k <= m) {
(dp[i][x] += dp[i - 1][k]) %= MOD;
}
}
}
} else {
for (int k : {a[i] - 1, a[i], a[i] + 1}) {
if (k >= 1 && k <= m) {
(dp[i][a[i]] += dp[i - 1][k]) %= MOD;
}
}
}
}
int result = 0;
for (int x = 1; x <= m; ++x) {
(result += dp[n - 1][x]) %= MOD;
}
cout << result << endl;
return 0;
}