Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #define _CRT_SECURE_NO_WARNINGS
- #include <algorithm>
- #include <bitset>
- #include <cstring>
- #include <cstdio>
- #include <cmath>
- #include <cctype>
- #include <cassert>
- #include <climits>
- #include <ctime>
- #include <iostream>
- #include <iomanip>
- #include <functional>
- #include <map>
- #include <string>
- #include <queue>
- #include <stack>
- #include <set>
- #include <unordered_set>
- #include <unordered_map>
- #include <vector>
- #include <array>
- #include <random>
- //#pragma GCC optimize("Ofast")
- //#pragma GCC target("avx,avx2,fma")
- //#pragma GCC optimization ("O3")
- //#pragma GCC optimization ("unroll-loops")
- using namespace std;
- #define all(x) x.begin(), x.end()
- #define int long long
- #define ld long double
- template <class T>
- istream& operator >>(istream& in, vector<T>& arr) {
- for (T& cnt : arr) {
- in >> cnt;
- }
- return in;
- }
- const int mod = 1e9 + 7;
- const int N = 501;
- int add(int a, int b) {
- if (a + b > mod) return a + b - mod;
- return a + b;
- }
- int sub(int a, int b) {
- if (a - b < 0) return a - b + mod;
- return a - b;
- }
- void solve() {
- int n, x, k; cin >> n >> x >> k;
- vector<vector<vector<int>>> dp(k + 1), new_dp(k + 1), pref(k + 1), new_pref(k + 1);
- for (int j = 0; j <= k; j++) {
- dp[j].resize(x + 1);
- new_dp[j].resize(x + 1);
- pref[j].resize(x + 1);
- new_pref[j].resize(x + 1);
- for (int lst = 0; lst <= x; lst++) {
- dp[j][lst].resize(2);
- new_dp[j][lst].resize(2);
- pref[j][lst].resize(2);
- new_pref[j][lst].resize(2);
- }
- }
- for (int lst = 1; lst <= x; lst++) {
- dp[0][lst][0] = 1;
- pref[0][lst][0] = add(pref[0][lst - 1][0], dp[0][lst][0]);
- }
- for (int i = 2; i <= n; i++) {
- for (int j = 0; j <= k; j++) {
- for (int lst = 1; lst <= x; lst++) {
- new_dp[j][lst][0] = add(dp[j][lst][0], dp[j][lst][1]);
- new_dp[j][lst][0] = add(new_dp[j][lst][0], sub(pref[j][x][0], pref[j][lst][0]));
- new_dp[j][lst][1] = add(pref[j][lst - 1][0], pref[j][lst - 1][1]);
- if (j) {
- new_dp[j][lst][0] = add(new_dp[j][lst][0], sub(pref[j - 1][x][1], pref[j - 1][lst][1]));
- }
- new_pref[j][lst][0] = add(new_pref[j][lst - 1][0], new_dp[j][lst][0]);
- new_pref[j][lst][1] = add(new_pref[j][lst - 1][1], new_dp[j][lst][1]);
- }
- }
- swap(dp, new_dp);
- swap(pref, new_pref);
- }
- cout << add(pref[k][x][0], pref[k][x][1]);
- }
- signed main()
- {
- ios_base::sync_with_stdio(false);
- cin.tie(0); cout.tie(0);
- //cout.precision(12);
- //freopen("substring-palindromes.in", "r", stdin);
- //freopen("substring-palindromes.out", "w", stdout);
- //prec();
- int _t = 1; //cin >> _t;
- while (_t--) {
- solve();
- //gen();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment