Guest User

1

a guest
Feb 8th, 2022
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.90 KB | None | 0 0
  1. #define _CRT_SECURE_NO_WARNINGS
  2. #include <algorithm>
  3. #include <bitset>
  4. #include <cstring>
  5. #include <cstdio>
  6. #include <cmath>
  7. #include <cctype>
  8. #include <cassert>
  9. #include <climits>
  10. #include <ctime>
  11. #include <iostream>
  12. #include <iomanip>
  13. #include <functional>
  14. #include <map>
  15. #include <string>
  16. #include <queue>
  17. #include <stack>
  18. #include <set>
  19. #include <unordered_set>
  20. #include <unordered_map>
  21. #include <vector>
  22. #include <array>
  23. #include <random>
  24.  
  25. //#pragma GCC optimize("Ofast")
  26. //#pragma GCC target("avx,avx2,fma")
  27. //#pragma GCC optimization ("O3")
  28. //#pragma GCC optimization ("unroll-loops")
  29. using namespace std;
  30.  
  31. #define all(x) x.begin(), x.end()
  32. #define int long long
  33. #define ld long double
  34.  
  35. template <class T>
  36. istream& operator >>(istream& in, vector<T>& arr) {
  37.     for (T& cnt : arr) {
  38.         in >> cnt;
  39.     }
  40.     return in;
  41. }
  42. const int mod = 1e9 + 7;
  43. const int N = 501;
  44.  
  45. int add(int a, int b) {
  46.     if (a + b > mod) return a + b - mod;
  47.     return a + b;
  48. }
  49.  
  50. int sub(int a, int b) {
  51.     if (a - b < 0) return a - b + mod;
  52.     return a - b;
  53. }
  54.  
  55. void solve() {
  56.     int n, x, k; cin >> n >> x >> k;
  57.     vector<vector<vector<int>>> dp(k + 1), new_dp(k + 1), pref(k + 1), new_pref(k + 1);
  58.     for (int j = 0; j <= k; j++) {
  59.         dp[j].resize(x + 1);
  60.         new_dp[j].resize(x + 1);
  61.         pref[j].resize(x + 1);
  62.         new_pref[j].resize(x + 1);
  63.         for (int lst = 0; lst <= x; lst++) {
  64.             dp[j][lst].resize(2);
  65.             new_dp[j][lst].resize(2);
  66.             pref[j][lst].resize(2);
  67.             new_pref[j][lst].resize(2);
  68.         }
  69.     }
  70.     for (int lst = 1; lst <= x; lst++) {
  71.         dp[0][lst][0] = 1;
  72.         pref[0][lst][0] = add(pref[0][lst - 1][0], dp[0][lst][0]);
  73.     }
  74.     for (int i = 2; i <= n; i++) {
  75.         for (int j = 0; j <= k; j++) {
  76.             for (int lst = 1; lst <= x; lst++) {
  77.                 new_dp[j][lst][0] = add(dp[j][lst][0], dp[j][lst][1]);
  78.                 new_dp[j][lst][0] = add(new_dp[j][lst][0], sub(pref[j][x][0], pref[j][lst][0]));
  79.                 new_dp[j][lst][1] = add(pref[j][lst - 1][0], pref[j][lst - 1][1]);
  80.                 if (j) {
  81.                     new_dp[j][lst][0] = add(new_dp[j][lst][0], sub(pref[j - 1][x][1], pref[j - 1][lst][1]));
  82.                 }
  83.                 new_pref[j][lst][0] = add(new_pref[j][lst - 1][0], new_dp[j][lst][0]);
  84.                 new_pref[j][lst][1] = add(new_pref[j][lst - 1][1], new_dp[j][lst][1]);
  85.             }
  86.         }
  87.         swap(dp, new_dp);
  88.         swap(pref, new_pref);
  89.     }
  90.     cout << add(pref[k][x][0], pref[k][x][1]);
  91. }
  92.  
  93. signed main()
  94. {
  95.     ios_base::sync_with_stdio(false);
  96.     cin.tie(0); cout.tie(0);
  97.     //cout.precision(12);
  98.     //freopen("substring-palindromes.in", "r", stdin);
  99.     //freopen("substring-palindromes.out", "w", stdout);
  100.     //prec();
  101.     int _t = 1; //cin >> _t;
  102.     while (_t--) {
  103.         solve();
  104.         //gen();
  105.     }
  106. }
Advertisement
Add Comment
Please, Sign In to add comment