Advertisement
a53

DifferenceK

a53
Sep 27th, 2020
120
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.96 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <algorithm>
  4.  
  5. using namespace std;
  6. using Vi = vector <int>;
  7. using V2i = vector <Vi>;
  8. constexpr auto MOD = 1000000007;
  9.  
  10.  
  11. int n, p, k, ans;
  12. Vi Arr;
  13. V2i DP;
  14.  
  15.  
  16. int main () {
  17. cin >> n >> p >> k;
  18. Arr.resize (n + 1), DP.assign (2, Vi (n + 1, 0));
  19. for (int i = 1; i <= n; ++ i)
  20. cin >> Arr[i];
  21.  
  22. for (int i = 1; i <= n; ++ i) {
  23. DP[i & 1].assign (n + 1, 0);
  24. for (int j = 1; j <= p; ++ j) {
  25. if (!Arr[i] || Arr[i] == j) {
  26. if (i == 1) DP[1][j] = 1;
  27. else for (int l = max (0, j - k); l <= min (p, j + k); ++ l) {
  28. DP[i & 1][j] += DP[1 ^ (i & 1)][l];
  29. if (DP[i & 1][j] >= MOD) DP[i & 1][j] -= MOD;
  30. }
  31. }
  32. }
  33. }
  34.  
  35. for (int i = 1; i <= p; ++ i) {
  36. ans += DP[n & 1][i];
  37. if (ans >= MOD) ans -= MOD;
  38. }
  39. cout << ans;
  40.  
  41. return 0;
  42. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement