[HNOI2008]越狱(bzoj1008)(组合数学+正难则反)

传送门

很好地体现了正难则反的思想。

总共的状态是m^n,不发生越狱则是要与前一个的宗教不同,那么这一个监狱的选择是m-1种。

总共不越狱的状态是m*(m-1)^(n-1)。

越狱的就是m^n-m*(m-1)^(n-1)

#include<bits/stdc++.h> 
#define LL long long
#define mod 100003
using namespace std;
LL read()
{
    LL f=1,x=0;char s=getchar();
    while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}
    while(s>='0'&&s<='9'){x=x*10+s-'0';s=getchar();}
    return x*f;
}
LL quick(LL a,LL x)
{
    LL ans=1;
    while(x)
    {
        if(x&1)ans=ans*a%mod;
        a=a*a%mod;
        x>>=1;
    }
    return ans%mod;
}
int main()
{
    LL m=read(),n=read();
    printf("%lld\n",((quick(m,n)-quick(m-1,n-1)*m%mod)%mod+mod)%mod);
}
/*
*/
View Code

 

转载于:https://www.cnblogs.com/yyys-/p/11436662.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值