-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathArrayDescription.java
More file actions
45 lines (37 loc) · 1.32 KB
/
ArrayDescription.java
File metadata and controls
45 lines (37 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
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
public class ArrayDescription {
static long mod = 1000000007;
public static void main (String[] args) throws IOException
{
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String s[] = br.readLine().split(" ");
int n = Integer.parseInt(s[0]);
int m = Integer.parseInt(s[1]);
String[] str = br.readLine().split(" ");
int[] v = new int[n];
for(int i = 0; i < n; i++) {
v[i] = Integer.parseInt(str[i]);
}
long[][] dp = new long[n+2][m+2];
for(int i = 1; i <= n; i++) {
for(int j = 1; j <= m; j++) {
if(i == 1) {
if(v[i-1] == 0 || v[i-1] == j) {
dp[i][j] = 1;
} else dp[i][j] = 0;
} else {
if(v[i-1] == 0 || v[i-1] == j) {
dp[i][j] = ((dp[i-1][j] + dp[i-1][j-1])% mod + dp[i-1][j+1]) % mod;
} else dp[i][j] = 0;
}
}
}
long ans = 0;
for(int j = 1; j <= m; j++) {
ans = (ans + dp[n][j]) % mod;
}
System.out.println(ans);
}
}