# Luogu 4492 [HAOI2018] Number of apple tree combinations

Source: Internet
Author: User

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

Related Keywords:
Related Article

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

## A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

• #### Sales Support

1 on 1 presale consultation

• #### After-Sales Support

24/7 Technical Support 6 Free Tickets per Quarter Faster Response

• Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.