# Luogu P4609 [FJOI2016]建筑师&&CF 960G Bandit Blues

CODE

#include<cstdio>
#define RI register int
#define CI const int&
using namespace std;
const int N=50000,M=200,mod=1e9+7;
int t,n,a,b,C[M+5][M+5],s[N+5][M+5];
inline int sum(CI a,CI b)
{
int t=a+b; return t>=mod?t-mod:t;
}
inline int min(CI a,CI b)
{
return a<b?a:b;
}
inline void init(void)
{
RI i,j; for (s[0][0]=i=1;i<=N;++i) for (j=min(i,M);j;--j)
s[i][j]=sum(s[i-1][j-1],1LL*(i-1)*s[i-1][j]%mod);
for (i=0;i<=M;++i) for (C[i][0]=C[i][i]=j=1;j<i;++j)
C[i][j]=sum(C[i-1][j],C[i-1][j-1]);
}
int main()
{
for (init(),scanf("%d",&t);t;--t)
{
scanf("%d%d%d",&n,&a,&b); if (!a||!b||n-1<a+b-2) { puts("0"); continue; }
printf("%d\n",1LL*s[n-1][a+b-2]*C[a+b-2][a-1]%mod);
}
return 0;
}

$S_n=\prod_{i=0}^{n-1}(x+i)$

CODE

#include<cstdio>
#include<vector>
#include<algorithm>
#define RI register int
#define CI const int&
#define pb push_back
using namespace std;
typedef vector <int> VT;
const int N=100005,mod=998244353;
int n,a,b;
inline int fact(CI n,int ret=1)
{
for (RI i=1;i<=n;++i) ret=1LL*ret*i%mod; return ret;
}
inline int quick_pow(int x,int p=mod-2,int mul=1)
{
for (;p;p>>=1,x=1LL*x*x%mod) if (p&1) mul=1LL*mul*x%mod; return mul;
}
inline int C(CI n,CI m)
{
return 1LL*fact(n)*quick_pow(1LL*fact(m)*fact(n-m)%mod)%mod;
}
class Poly_Solver
{
private:
int rev[N<<2],lim,p;
inline int sum(CI a,CI b)
{
int t=a+b; return t>=mod?t-mod:t;
}
inline int sub(CI a,CI b)
{
int t=a-b; return t<0?t+mod:t;
}
inline void swap(int& x,int& y)
{
int t=x; x=y; y=t;
}
inline void init(CI n)
{
for (lim=1,p=0;lim<=n;lim<<=1,++p);
for (RI i=0;i<lim;++i) rev[i]=(rev[i>>1]>>1)|((i&1)<<p-1);
}
inline void NTT(int *f,CI opt)
{
RI i; for (i=0;i<lim;++i) if (i<rev[i]) swap(f[i],f[rev[i]]);
for (i=1;i<lim;i<<=1)
{
int m=i<<1,D=quick_pow(3,~opt?(mod-1)/m:mod-1-(mod-1)/m);
for (RI j=0;j<lim;j+=m)
{
int W=1; for (RI k=0;k<i;++k,W=1LL*W*D%mod)
{
int x=f[j+k],y=1LL*f[i+j+k]*W%mod;
f[j+k]=sum(x,y); f[i+j+k]=sub(x,y);
}
}
}
if (!~opt)
{
int Inv=quick_pow(lim); for (RI i=0;i<lim;++i) f[i]=1LL*f[i]*Inv%mod;
}
}
inline VT merge(const VT& VA,const VT& VB)
{
static int A[N<<2],B[N<<2],n,m; VT VC; RI i;
for (n=VA.size(),i=0;i<n;++i) A[i]=VA[i];
for (m=VB.size(),i=0;i<m;++i) B[i]=VB[i];
init(n+m); fill(A+n,A+lim,0); fill(B+m,B+lim,0);
for (NTT(A,1),NTT(B,1),i=0;i<lim;++i) A[i]=1LL*A[i]*B[i]%mod;
for (NTT(A,-1),i=0;i<n+m-1;++i) VC.pb(A[i]); return VC;
}
public:
inline VT solve(CI l,CI r)
{
VT p; if (l==r) return p.pb(l),p.pb(1),p;
int mid=l+r>>1; return merge(solve(l,mid),solve(mid+1,r));
}
}P;
int main()
{
scanf("%d%d%d",&n,&a,&b); if (!a||!b||n-1<a+b-2) return puts("0"),0;
if (n==1) return puts("1"),0; VT ans=P.solve(0,n-2);
return printf("%d",1LL*ans[a+b-2]*C(a+b-2,a-1)%mod),0;
}
posted @ 2019-05-29 21:10 hl666 阅读(...) 评论(...) 编辑 收藏