# [caption] Luogu P5339 [TJOI2019] singing, dancing, rap and basketball

### Original question gate

#### So we just need violence calculation

#include <bits/stdc++.h>
#define ll long long
#define N 2005
#define mod 998244353
#define getchar nc
using namespace std;
inline char nc(){
static char buf[100000],*p1=buf,*p2=buf;
}
{
register int x=0,f=1;register char ch=getchar();
while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
while(ch>='0'&&ch<='9')x=(x<<3)+(x<<1)+ch-'0',ch=getchar();
return x*f;
}
inline void write(register int x)
{
if(!x)putchar('0');if(x<0)x=-x,putchar('-');
static int sta[20];register int tot=0;
while(x)sta[tot++]=x%10,x/=10;
while(tot)putchar(sta[--tot]+48);
}
inline int Min(register int a,register int b)
{
return a<b?a:b;
}
int n,a,b,c,d,lim;
ll fac[N],inv[N],f[N],res,ans;
int main()
{
fac[0]=fac[1]=inv[0]=inv[1]=1;
for(register int i=2;i<=n;++i)
fac[i]=fac[i-1]*i%mod;
for(register int i=2;i<=n;++i)
inv[i]=(mod-mod/i)*inv[mod%i]%mod;
for(register int i=2;i<=n;++i)
inv[i]=inv[i]*inv[i-1]%mod;
lim=Min(n>>2,Min(Min(a,b),Min(c,d)));
for(register int x=0,v;x<=lim;++x)
{
v=(x&1)?-1:1;
for(register int i=0;i<=n;++i)
f[i]=0;
for(register int i=0;i<=a-x;++i)
for(register int j=0;j<=Min(n-4*x-i,b-x);++j)
f[i+j]=(f[i+j]+inv[i]*inv[j])%mod;
res=0;
for(register int i=0;i<=c-x;++i)
for(register int j=0;j<=Min(n-4*x-i,d-x);++j)
res=(res+inv[i]*inv[j]%mod*f[n-4*x-i-j])%mod;
res=res*fac[n-3*x]%mod*inv[x]%mod;
ans=(ans+v*res)%mod;
}
write(ans<0?ans+mod:ans);
return 0;
}

Tags: PHP

Posted on Mon, 04 Nov 2019 16:14:41 -0500 by PURU