题目大意

题目分析
比较巧妙的转化。
若$n\gt m$无解,输出$0$,故$n\le m$。
设$f[i,j,k]$表示前$i$个位置,放了$j$个[,放了$k$个$)$的方案数。
设$g[i,j,k]$表示前$i$个位置,放了$j$个[,放了$k$个$)$的答案。
随便转移一下即可。
$i\in[1,m],j\in[0,\min(i,n)],k\in[0,j]$。
时间复杂度$\lt O(n^2m)\lt O(nm^2)$。
代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
| #include<algorithm> #include<iostream> #include<iomanip> #include<cstring> #include<cstdlib> #include<climits> #include<vector> #include<cstdio> #include<cmath> #include<queue> using namespace std;
typedef long long LL;
inline const int Get_Int() { int num=0,bj=1; char x=getchar(); while(x<'0'||x>'9') { if(x=='-')bj=-1; x=getchar(); } while(x>='0'&&x<='9') { num=num*10+x-'0'; x=getchar(); } return num*bj; }
const int maxn=100005; const LL mod=998244353;
void add(LL &x,LL v) { x+=v; if(x>=mod)x-=mod; }
LL Quick_Pow(LL a,LL b) { LL ans=1; for(a%=mod; b; b>>=1,a=a*a%mod)if(b&1)ans=ans*a%mod; return ans; }
int n,m,k; LL Pow[maxn],f[2][355][355],g[2][355][355];
int main() { n=Get_Int(); m=Get_Int(); k=Get_Int(); if(n>m) { puts("0"); return 0; } for(int i=1; i<=n; i++)Pow[i]=Quick_Pow(i,k); f[0][0][0]=0,g[0][0][0]=1; for(int i=1; i<=m; i++) { int now=i&1,last=now^1; for(int j=0; j<=min(i,n); j++) for(int k=0; k<=j; k++) { f[now][j][k]=g[now][j][k]=0; add(g[now][j][k],g[last][j][k]); if(j)add(g[now][j][k],g[last][j-1][k]); if(k)add(g[now][j][k],g[last][j][k-1]); if(j&&k)add(g[now][j][k],g[last][j-1][k-1]); add(f[now][j][k],f[last][j][k]); if(j)add(f[now][j][k],f[last][j-1][k]); if(k)add(f[now][j][k],f[last][j][k-1]); if(j&&k)add(f[now][j][k],f[last][j-1][k-1]); add(f[now][j][k],g[now][j][k]*Pow[j-k]%mod); } } printf("%lld\n",f[m&1][n][n]); return 0; }
|