F. Bags with Balls 第二类斯特林数

Bags with Balls

标号为奇数的个数为\(c=\frac{m+1}{2}\)

标号为偶数个数为\(w=m-c\)

答案显然为\(ANS=\sum_{i=1}^{n}C(n,i)c^iw^{n-i}i^k\)

直接算是\(O(n)\)的,但这道题\(n\)\(1e9\)

考虑第二类斯特林数化简\(i^k\)

\(x^k=\sum_{i=1}^kC(x,i)s(k,i)i!\)

\(ANS=\sum_{i=1}^{n}C(n,i)c^iw^{n-i}\sum_{j=1}^kC(i,j)s(k,j)j!=\sum_{j=1}^ks(k,j)\sum_{i=j}^{n}c^iw^{n-i}\frac{n!}{(i-j)!(n-i)!}=\sum_{j=1}^ks(k,j)\sum_{i=j}^{n}c^iw^{n-i}\frac{n!(n-j)!}{(n-j)!(i-j)!(n-i)!}=\sum_{j=1}^ks(k,j)\frac{n!}{(n-j)!}\sum_{i=j}^{n}c^iw^{n-i}C(n-j,n-i)=\sum_{j=1}^ks(k,j)\frac{n!}{(n-j)!}\sum_{i=0}^{n-j}c^ic^jw^{n-i-j}C(n-j,n-i-j)=\sum_{j=1}^ks(k,j)\frac{n!c^j}{(n-j)!}\sum_{i=0}^{n-j}c^iw^{n-j-i}C(n-j,i)=\sum_{j=1}^ks(k,j)\frac{n!c^j}{(n-j)!}(c+w)^{n-j}=\sum_{j=1}^ks(k,j)\frac{n!c^j}{(n-j)!}m^{n-j}\)

做完啦。

code
//#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<ctime>
#include<cctype>
#include<queue>
#include<deque>
#include<stack>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<cstring>
#include<string>
#include<ctime>
#include<cmath>
#include<cctype>
#include<cstdlib>
#include<queue>
#include<deque>
#include<stack>
#include<vector>
#include<algorithm>
#include<utility>
#include<bitset>
#include<set>
#include<map>
#define ll long long
#define db double
#define INF 1000000000
#define inf 100000000000000000ll
#define ldb long double
#define pb push_back
#define put_(x) printf("%d ",x);
#define putl_(x) printf("%lld ",x);
#define get(x) x=read()
#define putl(x) printf("%lld\n",x)
#define rep(p,n,i) for(int i=p;i<=n;i+=1)
#define fep(n,p,i) for(int i=n;i>=p;--i)
#define go(x) for(int i=lin[x],tn=ver[i];i;tn=ver[i=nex[i]])
#define pii pair<int,int>
#define mk make_pair
#define gf(x) scanf("%lf",&x)
#define pf(x) ((x)*(x))
#define uint unsigned long long
#define ui unsigned
#define sq sqrt
#define x(w) t[w].x
#define r(w) t[w].r
#define id(w) t[w].id
#define R(w) s[w].r
#define yy p<<1|1
#define zz p<<1
#define sum(w) t[w].sum
#define mod 998244353
#define sc(A) scanf("%d",&A)
#define scs(A) scanf("%s",A);
#define put(A) printf("%d\n",A)
#define min(x,y) (x>=y?y:x)
#define max(x,y) (x>=y?x:y)
#define sub(x,y) (x-y<0?x-y+mod:x-y)
using namespace std;
const int MAXN=2010,G=3;
int n,k,m,T,cnt,lim;
int s[MAXN][MAXN];
int fac[MAXN],inv[MAXN],a[MAXN],b[MAXN],w[MAXN],f[MAXN],rev[MAXN],g[MAXN];
inline int ksm(int b,int p)
{
	int cnt=1;
	while(p)
	{
		if(p&1)cnt=(ll)cnt*b%mod;
		b=(ll)b*b%mod;p=p>>1;
	}
	return cnt;
}
inline int C(int n,int m){return (ll)fac[n]*inv[m]%mod*inv[n-m]%mod;}
signed main()
{
	freopen("1.in","r",stdin);
	sc(T);
	s[0][0]=1;
	rep(1,2000,i)rep(1,2000,j)s[i][j]=((ll)j*s[i-1][j]+s[i-1][j-1])%mod;
	while(T--)
	{
		sc(n);sc(m);sc(k);
		int c=(m+1)>>1;
		int cc=n,kk=c,ww=ksm(m,n-1),inv=ksm(m,mod-2);
		int ans=0;
		rep(1,k,j)
		{
			ans=(ans+(ll)s[k][j]*cc%mod*kk%mod*ww)%mod;
			
			cc=(ll)cc*(n-j)%mod;
			kk=(ll)kk*c%mod;
			ww=(ll)ww*inv%mod;
		}
		put(ans);
	}
	return 0;
}
posted @ 2023-06-20 18:09  chdy  阅读(8)  评论(0编辑  收藏  举报