Subtask 1
Direct $n^2$ $DP $, it's ready.
Subtask 2
Use $f[i][j]$ to represent the current position as $i$, ending the number of scenarios for which the element is $j$.
Subtask 3
Look underneath.
Subtask 4
First, you can enumerate a sequence to select the same overlapping interval, and then some can be selected, and if so, ask for a rise.
Then it is easy to get the equation, which can be $n^4$ directly after discretization.
Then it does not optimize and look at the puzzle.
I think I can't write it.
Copy the code!
#include <map> #include <ctime> #include <cmath> #include <queue> #include <cstdio># Include <cstring> #include <iostream> #include <algorithm>using namespace std; #define F (I,j,k) for ( int i=j;i<=k;++i) #define D (I,J,K) for (int. i=j;i>=k;--i) #define LL Long Long#define MAXN 505#define MD 1000000007 in T N,b[maxn],a[maxn],siz[maxn],ls[maxn*2],top,ans=0,inv[maxn];int l[maxn],r[maxn],c[maxn],g[maxn],fac[maxn],inv_ FAC[MAXN]; int ksm (int a,int b,int p) {int ret=1;for (; b;a= (LL) a*a%p,b>>=1) if (b&1) ret= (LL) ret*a%md;return ret;} int Main ( {scanf ("%d", &n); fac[0]=1; F (i,1,maxn-1) fac[i]= (LL) fac[i-1]*i%md; Inv_fac[0]=1;inv_fac[1]=1; F (i,2,maxn-1) inv_fac[i]=ksm (FAC[I],MD-2,MD); F (i,1,maxn-1) inv[i]=ksm (I,MD-2,MD); F (i,1,n) scanf ("%d%d", &a[i],&b[i]), ls[++top]=a[i],ls[++top]=b[i]+1; Sort (ls+1,ls+top+1); Top=unique (ls+1,ls+top+1)-ls-1; F (i,1,n) {l[i]=lower_bound (ls+1,ls+top+1,a[i])-ls; R[i]=lower_bound (ls+1,ls+top+1,b[i]+1)-ls; } g[0]=1; C[0]=1; for (int j=1;j<top;++j) {int l=ls[j+1]-ls[j]; for (int i=1;i<=n;++i) c[i]= (LL) c[i-1]* (l+i-1)%md*inv[i]%md; for (int i=n;i>=1;--i) {if (L[i]<=j&&j+1<=r[i]) {int f=0,m= 1,c=l; for (int p=i-1;p>=0;--p) {f= (f+ (LL) c*g[p]%md)%md; if (L[p]<=j&&j+1<=r[p]) c=c[++m]; } g[i]= (g[i]+f)%md; }}} F (I,1,n) ans= (ans+g[i])%md; printf ("%d\n", ans);}
Bzoj 4584 [Apio2016] Rowing--Dynamic planning