-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayDescription.cpp
More file actions
42 lines (42 loc) · 880 Bytes
/
Copy pathArrayDescription.cpp
File metadata and controls
42 lines (42 loc) · 880 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
#include "bits/stdc++.h"
// #include <bits/stdc++.h>
using namespace std;
vector<vector<int> > dp;
int dynamic(int i,int j,vector<int> &arr,int n,int m) {
if(i<0 || i>=n){
return 0;
}
if(j==0){
if(arr[i]==0){
return 1;
}
return 0;
}
if(dp[i][j]!=-1){
return dp[i][j];
}
int ans=0;
if(arr[i]==0 || arr[i]==j){
ans=(dynamic(i-1,j-1,arr,n,m)+dynamic(i+1,j-1,arr,n,m))%1000000007;
}
else{
ans=dynamic(i-1,j-1,arr,n,m)%1000000007;
}
return dp[i][j]=ans;
}
int main() {
ios::sync_with_stdio(0);
cin.tie(0);
int n,m;
cin>>n>>m;
int arr[n];
for(int i=0;i<n;i++){
cin>>arr[i];
}
dp.resize(n,vector<int>(m,-1));
int ans=0;
for(int i=0;i<n;i++){
ans=(ans+dynamic(i,m-1,arr,n,m))%1000000007;
}
cout<<ans<<endl;
}