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

Original question gate This question zsy is about \ (O(n^2) \), and NTT\(O(n^2\log n) \). My problem is violence, \ (O(\frac) \), enough to pass Consi...

Original question gate

This question zsy is about \ (O(n^2) \), and NTT\(O(n^2\log n) \). My problem is violence, \ (O(\frac) \), enough to pass Consider setting \ (f(i) \) to indicate that there are at least \ (i \) groups in the sequence to discuss the number of cxk schemes In this way, the answer ans is: \[ans=\sum_^ (-1)^i f(i)\] Let's consider how to calculate \ (f(i) \) If the group to discuss cxk is considered as one element, there are \ (n-3*i \) elements in total We turn the problem into a number of multiple permutations The solution of multiple arrangement scheme number: Now there are \ (m \) different elements, each \ (I \) element has \ (a_i \), so the number of schemes is \[(\sum_^m a_i)! \times \prod_^m \frac\] 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; return p1==p2&&(p2=(p1=buf)+fread(buf,1,100000,stdin),p1==p2)?EOF:*p1++; } inline int read() { register int x=0,f=1;register char ch=getchar(); while(ch<'0'||ch>'9') 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() { n=read(),a=read(),b=read(),c=read(),d=read(); 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; }

4 November 2019, 16:14 | Views: 7072

Add new comment

For adding a comment, please log in
or create account

0 comments