#4705. 递增
题解
气死我了好不容易想出dp组合数写挂?
题解写的好清楚懒得写了...
代码
#include <bits/stdc++.h> #define LL long long using namespace std; const int N=105,P=998244353,I=(P+1)>>1; int n,f[N][N],g[N][N],jc[N],ny[N],B; LL l[N],r[N],b[N],L[N],R[N]; int K(int x,int y){ int z=1; for (;y;y>>=1,x=1ll*x*x%P) if (y&1) z=1ll*z*x%P; return z; } int inv(int x){ return 1ll*ny[x]*jc[x-1]%P; } int C(LL x,int y){ x=(x+y-1)%P;int v=1; for (int i=1;i<=y;i++) v=1ll*v*(x-i+1+P)%P*inv(i)%P; return v; } int W(){ for (int i=1;i<=n;i++){ if (L[i]>R[i]) return 0; b[++B]=L[i];b[++B]=R[i]+1; } sort(b+1,b+B+1); B=unique(b+1,b+B+1)-b-1;f[0][0]=1; for (int i=1;i<B;i++){ LL x=b[i],y=b[i+1]-1;f[i][0]=1; for (int j=1;j<=n;j++){ g[i][j]=g[i-1][j]; f[i][j]=f[i-1][j]; for (int k=j;k;k--){ if (L[k]<=x && y<=R[k]){ (g[i][j]+=(1ll*g[i-1][k-1]*C(y-x+1,j-k+1)%P+1ll*f[i-1][k-1]*C(y-x+1,j-k+1)%P*((x+y)%P)%P*I%P*(j-k+1)%P)%P)%=P; (f[i][j]+=1ll*f[i-1][k-1]*C(y-x+1,j-k+1)%P)%=P; } else break; } } } return g[B-1][n]; } int main(){ cin>>n;jc[0]=1; for (int i=1;i<=n;i++){ jc[i]=1ll*i*jc[i-1]%P; scanf("%lld",&l[i]); if (i==1) L[i]=l[i]; else L[i]=max(L[i-1],l[i]); } ny[n]=K(jc[n],P-2); for (int i=1;i<=n;i++) scanf("%lld",&r[i]);R[n]=r[n]; for (int i=n-1;i;i--) R[i]=min(R[i+1],r[i]); for (int i=n;i;i--) ny[i-1]=1ll*i*ny[i]%P; cout<<W()<<endl;return 0; }