-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path1746-array-description.cpp
70 lines (54 loc) · 1.38 KB
/
1746-array-description.cpp
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
#include <bits/stdc++.h>
using namespace std;
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define vi vector<int>
#define vl vector<long long>
#define pii pair<int, int>
#define pll pair<ll, ll>
#define umap unordered_map
#define uset unordered_set
#define rall(x) (x).rbegin(), (x).rend()
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define mp make_pair
const long long LLINF = LLONG_MAX;
const int INF = INT_MAX;
const int MOD = 1e9 + 7;
void solve() {
int n, m;
cin >> n >> m;
vi x(n);
for (int i = 0; i < n; ++i) {
cin >> x[i];
}
vector<vi> dp(n, vi(m + 1, 0));
for (int i = 1; i <= m; ++i) {
if (x[0] == 0 || x[0] == i) {
dp[0][i] = 1;
}
}
for (int i = 1; i < n; i++) {
for (int j = 1; j <= m; j++) {
if (x[i] == 0 || x[i] == j) {
dp[i][j] = dp[i - 1][j];
if (j > 1) dp[i][j] = (dp[i][j] + dp[i - 1][j - 1]) % MOD;
if (j < m) dp[i][j] = (dp[i][j] + dp[i - 1][j + 1]) % MOD;
}
}
}
int result = 0;
for (int i = 1; i <= m; ++i) {
result = (result + dp[n - 1][i]) % MOD;
}
cout << result << '\n';
}
int main() {
fastio
int tc = 1; // Number of test cases
// cin >> tc;
while (tc--) {
solve();
}
return 0;
}