Repository navigation
Expand file tree
/
Copy patharray_description.cpp
More file actions
85 lines (78 loc) · 1.95 KB
/
Copy patharray_description.cpp
File metadata and controls
85 lines (78 loc) · 1.95 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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
#include <bits/stdc++.h>
using namespace std;
int MOD = 1000000007;
int main() {
int n, m;
cin >> n >> m;
vector<int> x(n);
for(auto i=0;i<n;i++) {
cin >> x[i];
}
vector<pair<pair<int,int>,int>> v;
int answer = 1;
int i = 0;
while(i<=n) {
if(x[i]==0) {
int count = 0;
while(i<n && x[i]==0) {
i++;
count++;
}
if(i==n) {v.push_back({{0,0},count}); break;}
v.push_back({{0,x[i]},count});
if(i==n-1) break;
} else {
int temp = x[i];
int count = 0;
i++;
while(i<=n-1 && x[i]!=0) {
i++;
count++;
}
if(i==n) {v.push_back({{x[i],0},count}); break;}
v.push_back({{temp,x[i]}, count});
if(i==n-1) break;
}
}
vector<vector<int>> dp_2(m+1, vector<int>(m+1,0));
for(auto i=1;i<=m;i++) dp_2[0][i] = 1;
for(auto i=1;i<=m;i++) {
for(auto j=1;j<=m;j++) {
if(j==m) dp_2[i][j] = dp_2[i-1][j] + dp_2[i-1][j-1];
else dp_2[i][j] = ((dp_2[i-1][j] + dp_2[i-1][j-1])%MOD + dp_2[i-1][j+1])%MOD;
}
}
for(auto &alpha:v) {
if(alpha.first.first==0 && alpha.first.second==0) {
int ss = 0;
for(auto i=0;i<=m;i++) {
ss = (ss+dp_2[m-1][i])%MOD;
}
answer = (answer*ss)%MOD;
} else if(alpha.first.first==0) {
answer = (answer*dp_2[alpha.second][alpha.first.second])%MOD;
} else if(alpha.first.second==0) {
answer = (answer*dp_2[alpha.second][alpha.first.first])%MOD;
} else {
int temp1, temp2;
temp1 = max(alpha.first.first, alpha.first.second);
temp2 = min(alpha.first.first, alpha.first.second);
int count = alpha.second;
vector<vector<int>> dp(count+1, vector<int>(temp1+2,0));
for(auto j=temp2-1;j<=temp1+1 && j<=temp2+1;j++) {
if(j!=0) {
dp[0][j] = 1;
}
}
for(auto i=1;i<=count;i++) {
for(auto j=1;j<=temp1+1;j++) {
if(j==temp2) dp[i][j] = (dp[i-1][j] + dp[i-1][j-1])%MOD;
else dp[i][j] = ((dp[i-1][j]+dp[i-1][j-1])%MOD + dp[i-1][j+1])%MOD;
}
}
answer = (answer*dp[count][temp2])%MOD;
}
}
cout << answer << endl;
return 0;
}