Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <algorithm>
- using namespace std;
- using Vi = vector <int>;
- using V2i = vector <Vi>;
- constexpr auto MOD = 1000000007;
- int n, p, k, ans;
- Vi Arr;
- V2i DP;
- int main () {
- cin >> n >> p >> k;
- Arr.resize (n + 1), DP.assign (2, Vi (n + 1, 0));
- for (int i = 1; i <= n; ++ i)
- cin >> Arr[i];
- for (int i = 1; i <= n; ++ i) {
- DP[i & 1].assign (n + 1, 0);
- for (int j = 1; j <= p; ++ j) {
- if (!Arr[i] || Arr[i] == j) {
- if (i == 1) DP[1][j] = 1;
- else for (int l = max (0, j - k); l <= min (p, j + k); ++ l) {
- DP[i & 1][j] += DP[1 ^ (i & 1)][l];
- if (DP[i & 1][j] >= MOD) DP[i & 1][j] -= MOD;
- }
- }
- }
- }
- for (int i = 1; i <= p; ++ i) {
- ans += DP[n & 1][i];
- if (ans >= MOD) ans -= MOD;
- }
- cout << ans;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement