forked from namishkhanna/hacktoberfest2020
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ArrayDescription.cpp
72 lines (66 loc) · 1.5 KB
/
ArrayDescription.cpp
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
#include <iostream>
#include <vector>
#include <string>
#include <climits>
#include <set>
#include <algorithm>
using namespace std;
#define ll long long int
#define OJ \
freopen("input.txt", "r", stdin); \
freopen("output.txt", "w", stdout);
#define FIO \
ios_base::sync_with_stdio(false); \
cin.tie(NULL); \
cout.tie(NULL);
int main()
{
//OJ;
int mod = 1e9 + 7;
int n, m;
cin >> n >> m;
vector<vector<int>> dp(n, vector<int>(m + 1, 0));
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 i=1; i<=m; i++){
(ans+= dp[n-1][i])%=mod;
}
cout << ans << endl;
}