-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcses_1746.cpp
More file actions
62 lines (60 loc) · 1.32 KB
/
cses_1746.cpp
File metadata and controls
62 lines (60 loc) · 1.32 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
#include <iostream>
#include <assert.h>
#include <vector>
using namespace std;
constexpr int MOD = 1e9 + 7;
int main()
{
ios::sync_with_stdio(false);
cin.tie(0);
int n, m, tmp, a[187], b[187], *cur, *next;
cur = a, next = b;
cin >> n >> m;
for (int i = 0; i < 120; i++)
a[i] = 0, b[i] = 0;
cin >> tmp;
if (tmp == 0)
for (int i = 1; i <= m; i++)
cur[i] = 1;
else
cur[tmp] = 1;
n--;
while (n--)
{
cin >> tmp;
for (int i = 0; i < 120; i++)
next[i] = 0;
if (tmp == 0)
{
for (int i = 1; i <= m; i++)
{
for (int j = -1; j < 2; j++)
{
if (i + j == 0 || i + j > m)
continue;
next[i + j] += cur[i];
next[i + j] %= MOD;
}
}
}
else
{
for (int i = -1; i < 2; i++)
{
if (tmp + i == 0 || tmp + i > m)
continue;
next[tmp] += cur[tmp + i];
next[tmp] %= MOD;
}
}
swap(cur, next);
}
tmp = 0;
for (int i = 1; i <= m; i++)
{
tmp += cur[i];
tmp %= MOD;
}
cout << tmp << '\n';
return 0;
}