题目链接:https://www.lydsy.com/JudgeOnline/problem.php?id=1008

组合计数的简单题,可能越狱的方案数等于总方案数-不可能越狱的方案数,则:

总方案数为:mn

不可能越狱的方案数为m*(m-1)n-1,(第一个人有m种选法,之后的n-1个人有m-1种选法)。

#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const double eps = 1e-;
const ll INF = 9e18 + ;
const int maxn = 5e5 + ;
inline ll read() {
ll n = , f = ; char ch = getchar();
while (ch<'' || ch>'') { f = -, ch = getchar(); }
while (ch >= ''&&ch <= '') { n = n * + ch - '', ch = getchar(); }
return n * f;
}
ll qpow(ll a, ll b, ll mod) {
ll ans = ;
a %= mod;
while (b) {
if (b & )
ans = ans * a%mod;
a = a * a%mod;
b >>= ;
}
return ans;
}
int main() {
ll m, n;
m = read(), n = read();
printf("%lld\n", (qpow(m, n, ) - m * qpow(m - , n - , ) % + ) % );
}

[Bzoj1008][HNOI2008]越狱(组合计数)的更多相关文章

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

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

  2. bzoj1008 [HNOI2008]越狱

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

  3. BZOJ1008: [HNOI2008]越狱-快速幂+取模

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

  4. BZOJ1008 [HNOI2008]越狱 快速幂

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

  5. [BZOJ1008] [HNOI2008] 越狱 (数学)

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

  6. [bzoj1008](HNOI2008)越狱(矩阵快速幂加速递推)

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

  7. BZOJ1008: [HNOI2008]越狱(组合数)

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

  8. bzoj1008 [HNOI2008]越狱——快速幂

    题目:https://www.lydsy.com/JudgeOnline/problem.php?id=1008 (这样一道水题还因为忘记写 %lld WA了那么多遍) 发生越狱的状态数,就是全部状态 ...

  9. 【数论】【快速幂】bzoj1008 [HNOI2008]越狱

    根据 高中的数学知识 即可推出 ans=m^n-m*(m-1)^(n-1) .快速幂取模搞一下即可. #include<cstdio> using namespace std; typed ...

随机推荐

  1. 监听table滚动事件,滚动到底部时加载数据

    mounted() { this.$refs.scrollTable.addEventListener( 'scroll',(event) => { this.getDistance(event ...

  2. jsp页面转换时间戳

    <%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%> <fmt:fo ...

  3. 330-基于FMC接口的Kintex-7 XC7K325T PCIeX8 3U PXIe接口卡 光纤PCIe卡

    一.板卡概述      本板卡基于Xilinx公司的FPGAXC7K325T-2FFG900 芯片,pin_to_pin兼容FPGAXC7K410T-2FFG900 ,支持PCIeX8.64bit D ...

  4. java程序员必知的 8大排序

    Java常用的八种排序算法与代码实现 排序问题一直是程序员工作与面试的重点,今天特意整理研究下与大家共勉!这里列出8种常见的经典排序,基本涵盖了所有的排序算法. 1.直接插入排序 我们经常会到这样一类 ...

  5. jest操作 Elasticsearch

    package com.lgmall.search; import com.lgmall.search.esEntity.Article;import com.lgmall.search.esEnti ...

  6. IndexError: list index out of range的错误原因

    第1种可能情况list[index]index超出范围 第2种可能情况list是一个空的 没有一个元素进行list[0]就会出现该错误 ————————————————版权声明:本文为CSDN博主「m ...

  7. 对logistic回归分析的两重认识

    logistic回归,回归给人的直观印象只是要求解一个模型的系数,然后可以预测某个变量的回归值.而logistic回归在应用中多了一层含义,它经常应用于分类中.第一重认识:logistic是给真正的回 ...

  8. CentOS下安装Chrome浏览器

    1. 下载安装脚本, 在下载目录中,执行以下命令,将安装脚本下载到本地 wget https://intoli.com/install-google-chrome.sh 2.然后授予可执行权限 chm ...

  9. 使用 pyenv 管理 Python 版本

    http://einverne.github.io/post/2017/04/pyenv.html   Posted on 04/22/2017 by Ein Verne | View revisio ...

  10. NotSerializableException

    这个错误是实体类没有  继承  Serializeble.