Sample Input

2
2 2 3
3 2 2

Sample Output

0
4

# Solution

$f(i,j)=f(i-1,j-1)+f(i-1,j)*(m-1)$

$f_i=f_{i-1}\times g\\ =\sum_{j=0}^n \sum_{k=0}^j f_{i-1}(k)\times g(j-k)\\ =\sum_{j=0}^nf_{i-1}(j-1)+f_{i-1}(j)\times(m-1) \\ /*结合dp式考虑*/$

$g(0)=m-1\\ g(1)=1\\ 即g=m-1+x$

$f_n=g^n\\ =(m-1+x)^n\\ =\sum_{i=0}^nC_n^i (m-1)^{n-i}x^i\\ /*二项式定理*/$

$ans=\sum_{i=k}^nf_n(i)\\ =\sum_{i=k}^nC_n^i(m-1)^{n-i}$

# Code

#include<bits/stdc++.h>
#define int long long
using namespace std;
int x=0,f=1;char ch=getchar();
for(;!isdigit(ch);ch=getchar())if(ch=='-')f=-1;
for(;isdigit(ch);ch=getchar())x=x*10+ch-'0';
return x*f;
}
const int N=1e5+28,p=998244353;
int mul[N],inv[N],pw[N];
void Pre(int n=1e5){
mul[0]=mul[1]=inv[1]=pw[0]=1;
for(int i=2;i<=n;i++){
mul[i]=mul[i-1]*i%p;
inv[i]=(p-p/i)*inv[p%i]%p;
}
for(int i=2;i<=n;i++)inv[i]=inv[i]*inv[i-1]%p;
}
int C(int n,int m){
if(n==m)return 1;
return mul[n]*inv[m]%p*inv[n-m]%p;
}
signed main(){
//freopen("sequence.in","r",stdin);
//freopen("sequence.out","w",stdout);
Pre();
while(t--){
pw[0]=1;
for(int i=1;i<=n;i++){
pw[i]=1ll*pw[i-1]*(m-1)%p;
}
for(int i=k;i<=n;i++){
int tmp=1ll*C(n,i)*pw[n-i]%p;
ans=1ll*(ans+tmp)%p;
}
printf("%lld\n",ans);
}
return 0;
}
/*
2
2 2 3
3 2 2
*/


posted @ 2019-10-10 21:10  The_KOG  阅读(201)  评论(0编辑  收藏  举报