-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArray_Description.cpp
More file actions
32 lines (30 loc) · 837 Bytes
/
Array_Description.cpp
File metadata and controls
32 lines (30 loc) · 837 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
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int mod = 1e9+7;
int32_t main(){
ios_base::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
int n,m;
cin>>n>>m;
vector<int> v(n);
for(int i=0;i<n;i++) cin>>v[i];
vector<vector<int>> dp(n+1, vector<int>(m+2, 0));
if(v[0] == 0){
for(int j=1;j<=m;j++) dp[1][j] = 1;
}
else dp[1][v[0]] = 1;
for(int i=2;i<=n;i++){
for(int j=1;j<=m;j++){
if(v[i-1] != 0 && v[i-1] != j) continue;
if(j-1 > 0) dp[i][j] = (dp[i][j] + dp[i-1][j-1]) % mod;
dp[i][j] = (dp[i][j] + dp[i-1][j]) % mod;
if(j+1 <= m) dp[i][j] = (dp[i][j] + dp[i-1][j+1]) % mod;
}
}
int ans = 0;
for(int j=1;j<=m;j++) ans = (ans + dp[n][j]) % mod;
cout<<ans;
// khud se
}