码迷,mamicode.com
首页 > 其他好文 > 详细

BZOJ3157: 国王奇遇记 & 3516: 国王奇遇记加强版

时间:2014-05-14 10:45:13      阅读:357      评论:0      收藏:0      [点我收藏+]

标签:style   blog   class   code   java   c   

Sbubuko.com,布布扣ibubuko.com,布布扣=bubuko.com,布布扣k=1bubuko.com,布布扣nbubuko.com,布布扣kbubuko.com,布布扣ibubuko.com,布布扣mbubuko.com,布布扣kbubuko.com,布布扣bubuko.com,布布扣
我们有
(m?1)Sbubuko.com,布布扣ibubuko.com,布布扣bubuko.com,布布扣bubuko.com,布布扣bubuko.com,布布扣bubuko.com,布布扣bubuko.com,布布扣bubuko.com,布布扣bubuko.com,布布扣=bubuko.com,布布扣=bubuko.com,布布扣=bubuko.com,布布扣=bubuko.com,布布扣=bubuko.com,布布扣=bubuko.com,布布扣bubuko.com,布布扣mSbubuko.com,布布扣ibubuko.com,布布扣?Sbubuko.com,布布扣ibubuko.com,布布扣bubuko.com,布布扣bubuko.com,布布扣k=1bubuko.com,布布扣nbubuko.com,布布扣kbubuko.com,布布扣ibubuko.com,布布扣mbubuko.com,布布扣k+1bubuko.com,布布扣?bubuko.com,布布扣k=1bubuko.com,布布扣nbubuko.com,布布扣kbubuko.com,布布扣ibubuko.com,布布扣mbubuko.com,布布扣kbubuko.com,布布扣bubuko.com,布布扣bubuko.com,布布扣k=2bubuko.com,布布扣n+1bubuko.com,布布扣(k?1)bubuko.com,布布扣ibubuko.com,布布扣mbubuko.com,布布扣kbubuko.com,布布扣?bubuko.com,布布扣k=1bubuko.com,布布扣nbubuko.com,布布扣kbubuko.com,布布扣ibubuko.com,布布扣mbubuko.com,布布扣kbubuko.com,布布扣bubuko.com,布布扣nbubuko.com,布布扣ibubuko.com,布布扣mbubuko.com,布布扣n+1bubuko.com,布布扣+bubuko.com,布布扣k=1bubuko.com,布布扣nbubuko.com,布布扣mbubuko.com,布布扣kbubuko.com,布布扣((k?1)bubuko.com,布布扣ibubuko.com,布布扣?kbubuko.com,布布扣ibubuko.com,布布扣)bubuko.com,布布扣nbubuko.com,布布扣ibubuko.com,布布扣mbubuko.com,布布扣n+1bubuko.com,布布扣+bubuko.com,布布扣k=1bubuko.com,布布扣nbubuko.com,布布扣(bubuko.com,布布扣j=1bubuko.com,布布扣i?1bubuko.com,布布扣(?1)bubuko.com,布布扣i?jbubuko.com,布布扣(ibubuko.com,布布扣jbubuko.com,布布扣)kbubuko.com,布布扣jbubuko.com,布布扣mbubuko.com,布布扣kbubuko.com,布布扣)bubuko.com,布布扣nbubuko.com,布布扣ibubuko.com,布布扣mbubuko.com,布布扣n+1bubuko.com,布布扣+bubuko.com,布布扣j=0bubuko.com,布布扣i?1bubuko.com,布布扣(?1)bubuko.com,布布扣i?jbubuko.com,布布扣(ibubuko.com,布布扣jbubuko.com,布布扣)Sbubuko.com,布布扣jbubuko.com,布布扣bubuko.com,布布扣bubuko.com,布布扣bubuko.com,布布扣
直接按照这条式子O(nbubuko.com,布布扣2bubuko.com,布布扣)bubuko.com,布布扣 递推即可。

bubuko.com,布布扣
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long LL;
const LL mod=1000000007;
inline LL sqr(LL num){return num*num;}
LL mexp(LL a,LL b,LL p){return b?sqr(mexp(a,b>>1,p))%p*((b&1)?a:1)%p:1;}
LL fac[1100],facinv[1100],powm1[1100];
LL C(LL n,LL r){return fac[n]*facinv[r]%mod*facinv[n-r]%mod;}
LL n,m,s[1100];
int main(int argc, char *argv[])
{
    cin>>n>>m;
    if(m==1){cout<<n*(n+1)/2%mod<<endl;return 0;}
    fac[0]=1;for(int i=1;i<=m;i++)fac[i]=fac[i-1]*i%mod;
    facinv[m]=mexp(fac[m],mod-2,mod);facinv[0]=1;
    for(int i=m-1;i>=1;i--)facinv[i]=facinv[i+1]*(i+1)%mod;
    powm1[0]=1;for(int i=1;i<=m;i++)powm1[i]=powm1[i-1]*-1;
    s[0]=((mexp(m,n+1,mod)-m)%mod+mod)%mod*mexp(m-1,mod-2,mod);
    for(int i=1;i<=m;i++)
    {
        s[i]=mexp(n,i,mod)*mexp(m,n+1,mod)%mod;
        for(int j=0;j<i;j++)s[i]=((s[i]+powm1[i-j]*C(i,j)*s[j])%mod+mod)%mod;
        s[i]=s[i]*mexp(m-1,mod-2,mod)%mod;
    }
    cout<<s[m]<<endl;
    return 0;
}
bubuko.com,布布扣

 

BZOJ3157: 国王奇遇记 & 3516: 国王奇遇记加强版,布布扣,bubuko.com

BZOJ3157: 国王奇遇记 & 3516: 国王奇遇记加强版

标签:style   blog   class   code   java   c   

原文地址:http://www.cnblogs.com/zhuohan123/p/3726933.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!