-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray_description.cpp
More file actions
44 lines (42 loc) · 981 Bytes
/
array_description.cpp
File metadata and controls
44 lines (42 loc) · 981 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
40
41
42
43
44
//
// Created by innav_z3e3dq9 on 2/5/2025.
//
#include <bits/stdc++.h>
using namespace std;
int main() {
int mod = 1e9+7;
int n, m;
cin >> n >> m;
vector dp(n,vector<int>(m+1));
int x0;
cin >> x0;
if (x0 == 0) {
fill(dp[0].begin(), dp[0].end(), 1);
} else {
dp[0][x0] = 1;
}
for (int i = 1; i < n; i++) {
int x;
cin >> x;
if (x == 0) {
for (int j = 1; j <= m; j++) {
for (int k : {j-1,j,j+1}) {
if (k >= 1 && k <= m) {
(dp[i][j] += dp[i-1][k]) %= mod;
}
}
}
} else {
for (int k : {x-1, x, x+1}) {
if (k >= 1 && k <= m) {
(dp[i][x] += dp[i-1][k]) %= mod;
}
}
}
}
int ans = 0;
for (int j = 1; j <= m; j++) {
(ans += dp[n-1][j]) %= mod;
}
cout << ans << endl;
}