bzoj 4487: [Jsoi2015]染色問題

來源:互聯網
上載者:User

標籤:its   .net   容斥原理   printf   tail   sum   ++   logs   color   

先貼一個題解吧,最近懶得要死2333,可能是太弱的原因吧,總是扒題解,(甚至連題解都看不懂了),blog也沒更新,GG

http://blog.csdn.net/werkeytom_ftd/article/details/52527740

容斥原理真的很神奇233

 1 #include <bits/stdc++.h> 2 #define LL long long 3 using namespace std; 4  5 const int maxn=500; 6 const int mod=1e9+7; 7  8 int fac[maxn],inv[maxn]; 9 void pre()10 {11     fac[0]=1; for (int i=1; i<=400; i++) fac[i]=(LL)fac[i-1]*i%mod;12     inv[0]=inv[1]=1;13     for (int i=2; i<=400; i++) inv[i]=(LL)(mod-mod/i)*inv[mod%i]%mod;14     for (int i=2; i<=400; i++) inv[i]=(LL)inv[i]*inv[i-1]%mod;15 }16 int ksm(int x, int p)17 {18     int sum=1;19     for (;p;p>>=1,x=(LL)x*x%mod)20         if (p&1) sum=(LL)sum*x%mod;21     return sum;22 }23 int C(int n, int m)24 {25     return (LL)fac[n]*inv[m]%mod*inv[n-m]%mod;26 }27 28 int n,m,p,ans;29 int main()30 {31     cin>>n>>m>>p; pre();32     for (int i=0; i<=n; i++)33         for (int k=0; k<=p; k++)34         {35             int qwq=(LL)C(n,i)*C(p,k)%mod;36             int orz=ksm((1-ksm(k+1,i)+mod)%mod,m);37             qwq=(LL)qwq*orz%mod;38             if ((n+m+p-i-k)&1) qwq=-qwq;39             ans=(ans+qwq)%mod;40         }41     printf("%d\n",(ans+mod)%mod);42     return 0;43 }

 

bzoj 4487: [Jsoi2015]染色問題

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.