meaning of the title
Sol
It's not hard to think about this problem, but it's very troublesome to write, and then I went to look at the shortest code representation of loj, which can only be Orz
First of all, it is not difficult to find a property: the selectable interval must be shrinking, and the new selectable interval must be divided from some position of the old interval.
For example, \ (a = x \), when the maximum number less than \ (x \) is \ (l \), and the minimum number greater than \ (x \) is \ (R \), I choose a \ (a \). Obviously, if \ (T < x \), the minimum number greater than \ (t \) is \ (x \), the maximum number less than \ (t \) is \ (l \), \ (T > x \) similarly.
Then you can set \ (f[i][l][r] \) to represent the number of schemes whose location is in \ ([l,r] \). The transfer needs to be reversed.
Direct memory call search
Complexity \ (O(nr^3) \)
#include<bits/stdc++.h> #define Fin(x) freopen(#x".in", "r", stdin); using namespace std; const int MAXN = 50001, mod = 998244353; template<typename A, typename B> inline bool chmax(A &x, B y) template<typename A, typename B> inline bool chmin(A &x, B y) template<typename A, typename B> inline A mul(A x, B y) template<typename A, typename B> inline void add2(A &x, B y) template<typename A, typename B> inline int add(A x, B y) inline int read() { char c = getchar(); int x = 0, f = 1; while(c < '0' || c > '9') while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar(); return x * f; } int N, a[51], f[51][152][152]; int dfs(int x, int l, int r) { if(x > N) return 1; int &res = f[x][l][r]; if(~res) return res; res = 0; for(int i = max(1, l); i <= min(a[x], r); i++) { if(i == l || i == r) add2(res, dfs(x + 1, i, i)); else add2(res, add(add(dfs(x + 1, l, i), dfs(x + 1, i, r)), -dfs(x + 1, i, i) + mod)); } return res; } signed main() { memset(f, -1, sizeof(f)); N = read(); int mx = 0; for(int i = 1; i <= N; i++) a[i] = read(), chmax(mx, a[i]); cout << dfs(1, 0, mx + 1); return 0; }