Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Problem: F - |LIS| = 3
- // Contest: AtCoder - AtCoder Beginner Contest 237
- // URL: https://atcoder.jp/contests/abc237/tasks/abc237_f
- // Memory Limit: 1024 MB
- // Time Limit: 2000 ms
- //
- // Powered by CP Editor (https://cpeditor.org)
- #include <assert.h>
- #include <bits/stdc++.h>
- using namespace std;
- #define dbg(...) logger(#__VA_ARGS__, __VA_ARGS__)
- template <typename... Args> void logger(string vars, Args &&... values)
- {
- cerr << vars << " = ";
- string delim = "";
- (..., (cerr << delim << values, delim = ", "));
- cerr << endl;
- }
- template <class T> using mpq = priority_queue<T, vector<T>, greater<T>>;
- using ll = long long;
- using pii = pair<int, int>;
- int n, m;
- ll mod = 998244353;
- int main(int argc, char **argv)
- {
- cin >> n >> m;
- int b = m + 1;
- int state = b * b * b;
- vector<vector<ll>> dp(n + 1, vector<ll>(state));
- dp[0][0] = 1;
- for (int i = 1; i <= n; ++i) {
- for (int j = 0; j < state; ++j) {
- if (dp[i - 1][j]) {
- int a1 = j % b;
- int a2 = (j / b) % b;
- int a3 = (j / b / b) % b;
- for (int k = 1; k < b; ++k) {
- int ns = -1;
- if (a1 == 0) {
- ns = k;
- } else if (a2 == 0) {
- if (k <= a1) {
- ns = k;
- } else {
- ns = a1 + k * b;
- }
- } else if (a3 == 0) {
- if (k <= a1) {
- ns = k + a2 * b;
- } else if (k <= a2) {
- ns = a1 + k * b;
- } else {
- ns = a1 + a2 * b + k * b * b;
- }
- } else {
- if (k <= a1) {
- ns = k + a2 * b + a3 * b * b;
- } else if (k <= a2) {
- ns = a1 + k * b + a3 * b * b;
- } else if (k <= a3) {
- ns = a1 + a2 * b + k * b * b;
- } else {
- // invalid
- }
- }
- if (ns != -1) {
- dp[i][ns] = (dp[i][ns] + dp[i - 1][j]) % mod;
- }
- }
- }
- }
- }
- ll ans = 0;
- for (int i = 0; i < state; ++i) {
- ans += dp[n][i];
- }
- cout << (ans % mod) << endl;
- return 0;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement