https://www.luogu.org/problemnew/show/P4492
To find the contribution of the parent side of each numbered point, the combination number and factorial can be calculated.
I didn't think of it in the examination room.
Adjusted for a long time and long a long, not to be able to tune out, the sample has been over, just found that overflow, I am a zz.
1#include <cstdio>2#include <cstring>3#include <algorithm>4#include <cmath>5#include <iostream>6 using namespacestd;7 #defineLL Long Long8 LL N; LL p;9LL f[ .][ .]={};TenLL zu[ .][ .]={}; OneLL t[ .]={}; A intMain () { -scanf"%lld%lld",&n,&p); -LL ans=0; zu[0][0]=1; t[0]=1; the for(LL i=1; i<=n;i++) t[i]= (t[i-1]*i)%p; - for(LL i=1; i<=n;i++){ -zu[i][0]=1; - for(LL j=1; j<=i;j++) zu[i][j]= (zu[i-1][j]+zu[i-1][j-1])%p; + } - for(LL i=1; i<=n;i++){ +f[i][0]=1; A for(intj=1; j<=n;j++){ atF[i][j]= (f[i][j-1]* (i+j-1))%p; - } - } - for(LL i=2; i<=n;i++){ - for(LL j=n-i+1;j>0; j--){ -LL w= (zu[n-i][j-1]*T[J])%p; inW= (w* (t[i]*f[i-1][n-i-j+1]) (%p))%p; -W= (w* ((j* (n-j))%p)%p; toans= (ans+w)%p; + } - } theprintf"%lld\n", ans); * return 0; $}
View Code
Luogu 4492 [HAOI2018] Number of apple tree combinations