Luogu 4492 [HAOI2018]蘋果樹 組合數

來源:互聯網
上載者:User

標籤:int   bsp   lld   printf   階乘   view   define   class   技術分享   

https://www.luogu.org/problemnew/show/P4492

找每個編號的點的父邊的貢獻,組合數和階乘就能算了。

我考場上怎麼就是沒想到呢。

調了好久好久好久好久調不出來,範例一直過不了,剛剛發現是溢出了,我是個zz。

 1 #include<cstdio> 2 #include<cstring> 3 #include<algorithm> 4 #include<cmath> 5 #include<iostream> 6 using namespace std; 7 #define LL long long 8 LL n;LL p; 9 LL f[2010][2010]={};10 LL zu[2010][2010]={};11 LL t[2010]={};12 int main(){13     scanf("%lld%lld",&n,&p);14     LL ans=0; zu[0][0]=1; t[0]=1;15     for(LL i=1;i<=n;i++)t[i]=(t[i-1]*i)%p;16     for(LL i=1;i<=n;i++){17         zu[i][0]=1;18         for(LL j=1;j<=i;j++)zu[i][j]=(zu[i-1][j]+zu[i-1][j-1])%p;19     }20     for(LL i=1;i<=n;i++){21         f[i][0]=1;22         for(int j=1;j<=n;j++){23             f[i][j]=(f[i][j-1]*(i+j-1))%p;24         }25     }26     for(LL i=2;i<=n;i++){27         for(LL j=n-i+1;j>0;j--){28             LL w=(zu[n-i][j-1]*t[j])%p;29             w=(w*((t[i]*f[i-1][n-i-j+1])%p))%p;30             w=(w*((j*(n-j))%p))%p;31             ans=(ans+w)%p;32         }33     }34     printf("%lld\n",ans);35     return 0;36 }
View Code

 

Luogu 4492 [HAOI2018]蘋果樹 組合數

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.