标签:出现 mod names tin type ons 链接 一起 一个
题解:
代码如下
#include<bits/stdc++.h> using namespace std; typedef long long LL; const LL mod=998244353; LL qpow(LL x,LL n) //求x^n%mod { LL ret=1; for(; n; n>>=1) { if(n&1) ret=ret*x%mod; x=x*x%mod; } return ret; } int C(LL a,LL b=2) { return a*(a-1)%mod*qpow(b,mod-2)%mod; } const int N=1e3+5; LL dp[N][N]; void init() { dp[1][1]=2; for(int i=1;i<N;i++) { dp[i+1][0]=2*dp[i][0]%mod*C(2*i+1,2)%mod+ 2*dp[i][1]%mod*2*i%mod+ 2*dp[i][2]%mod; dp[i+1][0]%=mod; for(int j=1;j<=i+1;j++) { dp[i+1][j]=2*dp[i][j-1]%mod*(2*i+1-(j-1))%mod+ 2*dp[i][j]%mod*(j+C(2*i+1-j,2))%mod+ 2*dp[i][j+1]%mod*((j+1)*(2*i+1-(j+1))%mod)%mod+ 2*dp[i][j+2]%mod*C(j+2,2)%mod; dp[i+1][j]%=mod; } } } int main() { init(); LL n,d; while(~scanf("%lld%lld",&n,&d)) { LL ret=0; if(n==1) { printf("%lld\n",2*d%mod); continue; } for(int i=0;i<=n;i++) ret=(ret+dp[n][i]*qpow(d,i)%mod)%mod; printf("%lld\n",ret); } }
标签:出现 mod names tin type ons 链接 一起 一个
原文地址:https://www.cnblogs.com/Just--Do--It/p/9460904.html