BZOJ 1008: [HNOI2008]越狱 组合数学
原题链接:http://www.lydsy.com/JudgeOnline/problem.php?id=1008
题解:
就很傻逼的组合数学啊。。。
$$ans=M^N-M*(M-1)^{(N-1)}$$
代码:
/**************************************************************
Problem: 1008
User: HarryGuo2012
Language: C++
Result: Accepted
Time:0 ms
Memory:1272 kb
****************************************************************/ #include<iostream>
#include<cstring>
#include<vector>
#include<cstdio>
using namespace std; typedef long long ll; const ll mod=; ll Pow(ll a,ll b) {
ll res = ;
while (b) {
if (b & )res = (res * a) % mod;
a = (a * a) % mod;
b >>= ;
}
return res;
} ll M,N; int main() {
scanf("%lld%lld", &M, &N);
printf("%lld\n", (M*mod + Pow(M, N) - M * Pow(M - , N - )) % mod);
return ;
}
BZOJ 1008: [HNOI2008]越狱 组合数学的更多相关文章
- BZOJ 1008: [HNOI2008]越狱 快速幂
1008: [HNOI2008]越狱 Description 监狱有连续编号为1...N的N个房间,每个房间关押一个犯人,有M种宗教,每个犯人可能信仰其中一种.如果相邻房间的犯人的宗教相同,就可能发生 ...
- BZOJ 1008 [HNOI2008]越狱
1008: [HNOI2008]越狱 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 5166 Solved: 2242[Submit][Status] ...
- BZOJ 1008 [HNOI2008]越狱 (简单排列组合 + 快速幂)
1008: [HNOI2008]越狱 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 10503 Solved: 4558[Submit][Status ...
- BZOJ 1008 [HNOI2008]越狱 排列组合
1008: [HNOI2008]越狱 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 4788 Solved: 2060[Submit][Status] ...
- BZOJ 1008: [HNOI2008]越狱-快速幂/取模
1008: [HNOI2008]越狱 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 8689 Solved: 3748 Description 监狱有 ...
- bzoj 1008: [HNOI2008]越狱 数学
1008: [HNOI2008]越狱 Time Limit: 1 Sec Memory Limit: 162 MB[Submit][Status][Discuss] Description 监狱有连 ...
- BZOJ 1008: [HNOI2008]越狱【组合】
很少有的思路秒解.题意可以描述成对长度为n的格子有m种染色方案,问存在相邻两个格子同色的方案数,正难则反易,考虑问题的背面任意两个相邻的格子都不同色,第一个格子可以涂任意一种颜色m种可能,剩下的n-1 ...
- 1008: [HNOI2008]越狱(计数问题)
1008: [HNOI2008]越狱 Time Limit: 1 Sec Memory Limit: 162 MBSubmit: 11361 Solved: 4914[Submit][Status ...
- 【BZOJ】1008: [HNOI2008]越狱(组合数学)
题目 题目描述 监狱有连续编号为1...N的N个房间,每个房间关押一个犯人,有M种宗教,每个犯人可能信仰其中一种.如果相邻房间的犯人的宗教相同,就可能发生越狱,求有多少种状态可能发生越狱 输入输出格式 ...
随机推荐
- 使用TensorFlow的卷积神经网络识别手写数字(3)-识别篇
from PIL import Image import numpy as np import tensorflow as tf import time bShowAccuracy = True # ...
- LeetCode(260) Single Number III
题目 Given an array of numbers nums, in which exactly two elements appear only once and all the other ...
- Linux学习-软件管理员简介
Linux 界的两大主流: RPM 与 DPKG 目前在 Linux 界软件安装方式最常见的有两种,分别是: dpkg: 这个机制最早是由 Debian Linux 社群所开发出来的,透过 dpkg ...
- 金阳光Android自动化测试第一季
第一季:http://www.chuanke.com/v1983382-106000-218422.html 第一节:Android自动化预备课程基础(上) 1. 基于坐标点触屏:monkey ...
- Oracle数据库的日常使用命令
1. 启动和关闭数据库 sqlplus /nolog; SQL >conn / as sysdba;(上面的两条命令相当于sqlplus ‘/as sysdba’) SQL >st ...
- 大数据学习——kettle的简单使用
1 生成随机数保存到本地文件 新建转换--输入--生成随机数--输出--文本文件输出--保存到本地文件 2 在线预览生成结果 3 字段选择 4 增加常量 5 生成多条数据 右键生成随机数--改变开始复 ...
- 【JavaScript】关于 setInterval() 调用函数方法的一次实验
实验主题: setInterval() 方法是 JS 中比较常用的一个方法.setInterval() 方法可以按照指定的周期 ( 毫秒 ) 来调用函数方法或计算表达式. setInterval() ...
- .Net程序员自学dump分析教程
文章:.Net程序员自学dump分析教程 可以分析内存状态.
- C++之Effective STL学习笔记Item20
Q:假设我们现在需要一个string*的set,我们向其插入一些动物到这个set中: set<string*> ssp; // ssp = “set of string ptrs” ssp ...
- kb-07线段树-08--区间开根
/* hdu-4027 题目:区间开根求和查询: 因为是开根,所以要更新的话就要更新到叶子节点.如果区间里全是1或是0的话就步用继续更新了,查询的时候正常查询: */ #include<iost ...