Guest User

2

a guest
Feb 8th, 2022
172
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 2.89 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.  
  44. int add(int a, int b) {
  45.     if (a + b > mod) return a + b - mod;
  46.     return a + b;
  47. }
  48.  
  49. int sub(int a, int b) {
  50.     if (a - b < 0) return a - b + mod;
  51.     return a - b;
  52. }
  53.  
  54. void solve() {
  55.     int n, x, k; cin >> n >> x >> k;
  56.     vector<vector<vector<int>>> dp(k + 1), new_dp(k + 1), pref(k + 1), new_pref(k + 1);
  57.     for (int j = 0; j <= k; j++) {
  58.         dp[j].resize(x + 1);
  59.         new_dp[j].resize(x + 1);
  60.         pref[j].resize(x + 1);
  61.         new_pref[j].resize(x + 1);
  62.         for (int lst = 0; lst <= x; lst++) {
  63.             dp[j][lst].resize(2);
  64.             new_dp[j][lst].resize(2);
  65.             pref[j][lst].resize(2);
  66.             new_pref[j][lst].resize(2);
  67.         }
  68.     }
  69.     for (int lst = 1; lst <= x; lst++) {
  70.         dp[0][lst][0] = 1;
  71.         pref[0][lst][0] = add(pref[0][lst - 1][0], dp[0][lst][0]);
  72.     }
  73.     for (int i = 2; i <= n; i++) {
  74.         for (int j = 0; j <= k; j++) {
  75.             for (int lst = 1; lst <= x; lst++) {
  76.                 new_dp[j][lst][0] = add(dp[j][lst][0], dp[j][lst][1]);
  77.                 new_dp[j][lst][0] = add(new_dp[j][lst][0], sub(pref[j][x][0], pref[j][lst][0]));
  78.                 new_dp[j][lst][1] = add(pref[j][lst - 1][0], pref[j][lst - 1][1]);
  79.                 if (j) {
  80.                     new_dp[j][lst][0] = add(new_dp[j][lst][0], sub(pref[j - 1][x][1], pref[j - 1][lst][1]));
  81.                 }
  82.                 new_pref[j][lst][0] = add(new_pref[j][lst - 1][0], new_dp[j][lst][0]);
  83.                 new_pref[j][lst][1] = add(new_pref[j][lst - 1][1], new_dp[j][lst][1]);
  84.             }
  85.         }
  86.         swap(dp, new_dp);
  87.         swap(pref, new_pref);
  88.     }
  89.     cout << add(pref[k][x][0], pref[k][x][1]);
  90. }
  91.  
  92. signed main()
  93. {
  94.     ios_base::sync_with_stdio(false);
  95.     cin.tie(0); cout.tie(0);
  96.     //cout.precision(12);
  97.     //freopen("substring-palindromes.in", "r", stdin);
  98.     //freopen("substring-palindromes.out", "w", stdout);
  99.     //prec();
  100.     int _t = 1; //cin >> _t;
  101.     while (_t--) {
  102.         solve();
  103.         //gen();
  104.     }
  105. }
Advertisement
Add Comment
Please, Sign In to add comment