Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- #include <numeric>
- #include <cmath>
- #include <climits>
- #include <queue>
- using namespace std;
- const int N = 1e5, mod = 1e9 + 7;
- int dp[N][101], a[N+1], n, m, ans = 0;
- void read()
- {
- cin >> n >> m;
- for (int i = 1; i <= n; ++ i)
- {
- cin >> a[i];
- }
- }
- void solve()
- {
- if (a[1] == 0)
- {
- for (int i = 1; i <= m; ++ i)
- {
- dp[1][i] = 1;
- }
- }
- else
- {
- dp[1][a[1]] = 1;
- }
- for (int i = 2; i <= n; ++ i)
- {
- if (a[i] == 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][j] + dp[i-1][k]) % mod;
- }
- }
- }
- }
- else
- {
- for (int k : {a[i] - 1, a[i], a[i] + 1})
- {
- if (k >= 1 && k <= m)
- {
- dp[i][a[i]] = (dp[i][a[i]] + dp[i-1][k]) % mod;;
- }
- }
- }
- }
- for (int i = 1; i <= m; ++ i)
- {
- ans = (ans + dp[n][i]) % mod;
- }
- cout << ans;
- }
- int main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(nullptr);
- read();
- solve();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement