题解:

要求有几种方案可以越狱,可以用总方案-不会越狱的方案

那么总方案就是m^n

那么考虑不会越狱的方案

显然第一个人有m中,后面都是m-1中(和前一个不一样)

答案就是m^n-m*(m-1)^(n-1)

代码:

  1. #include<bits/stdc++.h>
  2. using namespace std;
  3. typedef long long ll;
  4. const ll M=;
  5. ll n,m;
  6. ll ksm(ll x,ll y)
  7. {
  8. if (y==)return ;
  9. ll z=ksm(x,y/);
  10. z*=z;z%=M;
  11. if (y%==)(z*=x)%=M;
  12. return z;
  13. }
  14. int main()
  15. {
  16. scanf("%lld%lld",&m,&n);
  17. printf("%lld",(ksm(m,n)-m*ksm(m-,n-)%M+M)%M);
  18. }

bzoj1008的更多相关文章

  1. BZOJ1008 [HNOI2008]越狱 快速幂

    欢迎访问~原文出处——博客园-zhouzhendong 去博客园看该题解 题目传送门 - BZOJ1008 题意概括 监狱有连续编号为1...N的N个房间,每个房间关押一个犯人,有M种宗教,每个犯人可 ...

  2. 洛谷3197&bzoj1008 越狱

    洛谷3197&bzoj1008 越狱 Luogu bzoj 题解 所有状态减合法状态.SBT 答案为\(m^n-m*(m-1)^{n-1}\)太SB不解释 注意取膜的问题.相减可能减出负数,而 ...

  3. bzoj1008: [HNOI2008]越狱 数学公式+快速幂

    bzoj1008: [HNOI2008]越狱      O(log N)---------------------------------------------------------------- ...

  4. bzoj1008快速面

    快速面裸题(显然的m^n-m*(m-1)^(n-1)) 然后,,,就没有然后了 #include <cstdio> #define wzf2000 100003 long long n,m ...

  5. bzoj1008 [HNOI2008]越狱

    1008: [HNOI2008]越狱 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 5099  Solved: 2207 Description 监狱有 ...

  6. 【BZOJ1008】1008: [HNOI2008]越狱 简单组合数学+快速幂

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

  7. [HNOI2008],[bzoj1008] 越狱(dp+组合数学)

    题目传送门:http://www.lydsy.com/JudgeOnline/problem.php?id=1008 Description 监狱有连续编号为1...N的N个房间,每个房间关押一个犯人 ...

  8. BZOJ1008 /乘法原理+快速幂 解题报告

    1008: [HNOI2008]越狱 Description 监狱有连续编号为1...N的N个房间,每个房间关押一个犯人,有M种宗教,每个犯人可能信仰其中一种.如果相邻房间的犯人的宗教相同,就可能发生 ...

  9. 【BZOJ1008】【HNOI2008】越狱(数学排列组合题)

    1008: [HNOI2008]越狱 Time Limit: 1 Sec  Memory Limit: 162 MBSubmit: 3140  Solved: 1317[Submit][Status] ...

  10. BZOJ-1008 越狱 数论快速幂

    1008: [HNOI2008]越狱 Time Limit: 1 Sec Memory Limit: 162 MB Submit: 6192 Solved: 2636 [Submit][Status] ...

随机推荐

  1. CreateDirectory 创建文件夹 C\C++

    函数原型: CreateDirectory( LPCTSTR lpPathName, LPSECURITY_ATTRIBUTES lpSecurityAttributes ); 简介: CreateD ...

  2. 通过gevent实现【单线程】下的多socket并发

    server import sys import socket import time import gevent from gevent import socket,monkey monkey.pa ...

  3. python 字节数组和十六进制字符串互转

    . 字节数组 --> 十六进制字符串 >>> a = 'ab' >>> a.encode('hex') ' . 十六进制字符串 --> 字节数组 > ...

  4. python ros 创建节点订阅robot_pose

    建立文件夹hello_rospy,再在该目录下建立子目录src,cd到该src目录,运行如下命令创建工作包 catkin_create_pkg beginner_tutorials std_msgs ...

  5. Java 集合、Iterator迭代器、泛型等

    01集合使用的回顾 A:集合使用的回顾 a.ArrayList集合存储5个int类型元素 public static void main(String[] args) { ArrayList<I ...

  6. [ios]MKMapView中使用MKPolyline画线

    参考:http://blog.sina.com.cn/s/blog_9e8867eb0101dt76.html 首先在MapView.h中 #import <MapKit/MapKit.h> ...

  7. English trip -- VC(情景课) 8 B job duties 工作职责

    Vocabulary focus  核心词汇 She is a receptionist. She answers the phone. She is a cashier She counts mon ...

  8. LeetCode--190--颠倒二进制位

    问题描述: 颠倒给定的 32 位无符号整数的二进制位. 示例: 输入: 43261596 输出: 964176192 解释: 43261596 的二进制表示形式为 000000101001010000 ...

  9. Rspec: everyday-rspec实操。FactoryBot预构件 (rspec-expectations gem 查看匹配器) 1-4章

    总文档连接: RSpec.info/documentation/ 包括core, expectiation,rails , mock, 点击最新版本,然后右上角搜索class, method. 第3章 ...

  10. 3-19(晚) require_relative 和 require. === operator的解释。

    kernel#require_relative Ruby tries to load the library named string relative to the requiring file's ...