-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy patharray_discription.cpp
More file actions
61 lines (58 loc) · 1.24 KB
/
Copy patharray_discription.cpp
File metadata and controls
61 lines (58 loc) · 1.24 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
58
59
60
61
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define mod (int)(1e9+7)
#define sz(s) (int)s.size()
#define all(v) v.begin(),v.end()
#define fill0(dp) memset(dp,0,sizeof(dp))
#define fill(dp) memset(dp,-1,sizeof(dp))
#define input(v) for (auto &i : v) cin >> i;
#define print(v) for (auto &j : v) cout << j << " "; cout << "\n";
vector<int>x;
int n,m;
int dp[(int)(1e5)+1][101];
int f(int i,int back)
{
if(back < 1 or back > m) return 0;
if(i==n) return 1;
if(dp[i][back]!=-1) return dp[i][back]%mod;
if(x[i])
{
if(abs(x[i]-back)>1) return 0;
else
{
return dp[i][back] = f(i+1,x[i])%mod;
}
}
else
{
return dp[i][back] = (f(i+1,back)%mod+f(i+1,back-1)%mod+f(i+1,back+1)%mod)%mod;
}
}
void solve()
{
fill(dp);
cin>>n>>m;
x.resize(n);
input(x);
int ans=0;
if(x[0]) cout<<f(1,x[0]);
else
{
for(int i=1;i<=m;i++)
{
ans = (ans + f(1,i)%mod)%mod;
}
cout<<ans%mod<<"\n";
exit(0);
}
}
signed main()
{
ios_base::sync_with_stdio(false);
cin.tie(nullptr);cout.tie(nullptr);
int testcases=1;
//cin>>testcases;
while(testcases--) solve();
return 0;
}