Directly on the puzzle
1#include <cstdio>2#include <iostream>3#include <cmath>4#include <cstring>5#include <algorithm>6 #definell Long Long7 Const intMod=1000000009, n= the;8ll jc[n+Ten],jcny[n+Ten],jcnys[n+Ten],k[n+Ten],p[n+Ten],f[n+Ten];9 intRead () {Ten intt=0, f=1;CharCh=GetChar (); One while(ch<'0'|| Ch>'9'){if(ch=='-') f=-1; ch=GetChar ();} A while('0'<=ch&&ch<='9') {t=t*Ten+ch-'0'; ch=GetChar ();} - returnt*F; - } the intPow (intAintN) { - intres=1; - while(n) { - if(n%2) res= ((LL) res*a)%Mod; +A= (LL) a*a)%Mod; -N/=2; + } A returnRes; at } - intMain () { -jc[0]=1; - for(intI=1; i<= the; i++) jc[i]= (LL) (jc[i-1]*i)%Mod; -jcny[ the]=pow (jc[ the],mod-2)%Mod; - for(intI=2999; i>=0; i--) jcny[i]= (LL) jcny[i+1]* (i+1)%Mod; in for(intI=0; i<= the; i++) jcnys[i]= (LL) jcny[i]*jcny[i]%Mod; - for(intI=0; i<= the; i++) to if((i&1) &&jcny[i]) k[i]=mod-jcny[i];Elsek[i]=Jcny[i]; + intn=read (); - for(intI=1; i<=n;i++) { the intX=read ();p [x]++; * } $f[0]=1;Panax Notoginseng for(intk=1, tot=0; k<=n;k++){ - if(p[k]==0)Continue; thetot+=P[k]; + for(inti=tot;i>=0; i--){ Af[i]= (LL) f[i]*jcnys[p[k]]%Mod; the for(intj=1; j<=p[k]&&j<=i;j++) +f[i]= (LL) f[i-j]*k[j]%mod*jcnys[p[k]-j]+f[i])%Mod; - } $ } $ll ans=0; - for(intI=0; i<=n;i++) -ans= (LL) Jc[n-i]*f[i]+ans)%Mod; the for(intI=1; i<=n;i++) -ans= (LL) ans*jc[p[i]]%Mod;Wuyiprintf"%i64d\n", ans); the}
FJ Provincial team Training DAY4 T1