1008: [HNOI2008]越狱

1008: [HNOI2008]越狱

Time Limit: 1 Sec  Memory Limit: 162 MB
Submit: 9035  Solved: 3925
[Submit][Status][Discuss]

Description

  监狱有连续编号为1...N的N个房间,每个房间关押一个犯人,有M种宗教,每个犯人可能信仰其中一种。如果
相邻房间的犯人的宗教相同,就可能发生越狱,求有多少种状态可能发生越狱

Input

  输入两个整数M,N.1<=M<=10^8,1<=N<=10^12

Output

  可能越狱的状态数,模100003取余

Sample Input

2 3

Sample Output

6

HINT

 

  6种状态为(000)(001)(011)(100)(110)(111)

 

Source

/*
 * Author: lyucheng
 * Created Time:  2017年05月17日 星期三 09时24分52秒
 * File Name: BZOJ-1008.cpp
 */
/* 题意:有n间监狱,每个监狱住着一个犯人,有m种信仰,每个犯人都对有一种信仰,如果两个相邻的犯人的信仰相同,那么就会发生越狱
 *      问你总共有多少种越狱的情况
 *
 * 思路:排列组合问题,总的情况有m^n种,考虑无法越狱的情况:第一个犯人有m中信仰,接下来每个犯人都有m-1中信仰(简单画画就会
 *      出结果),那么得到结果:m^n-m*(m-1)^(n-1)
 * */
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <time.h>
#define LL long long
using namespace std;
#define mod 100003
LL power(LL a,LL b){
    if(b==0) return 1;
    LL cnt=power(a,b/2);
    cnt=cnt*cnt%mod;
    if(b%2==1) cnt=cnt*a%mod;
    return cnt;
}
LL m,n;
int main(int argc, char* argv[])
{
     //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout;
    scanf("%lld%lld",&m,&n);
    LL res=power(m,n);
    res=(res-m*power(m-1,n-1)%mod)%mod;
    while(res<mod) res+=mod;
    printf("%lld\n",res%mod);
    return 0;
}

 

转载于:https://www.cnblogs.com/wuwangchuxin0924/p/6868193.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值