C. Shaass and Lights 组合数学
http://codeforces.com/contest/294/problem/C
把那个数组n分段了,那么有两类。
1、开头和端点那些,就是只有一端在开始的,这个时候,要开完这些灯,只能循序渐进,1--2--3--4
2、第二类就是中间那些,两端都可以开始,那些段的开灯次数是2^(len - 1)。因为这个就是看成一个双端队列,每一次都可以从头或者尾取数字,所以每次的决策有2种,然后最后一次只有一个数,所以直接是它。
现在就是把他们若干段合并后,有多少种情况的问题了。
其实就是
A1、B1、C1
A2、B2、C2
A3、B3、C3
的排列问题,而且,B1要放的话,首先需要A1在它前面,同理C3要放的话,需要A3和B3在它前面。
那么这个其实就是平均分堆问题。
A1、B1、C1其实只有一种合法的排列,就是A1 B1 C1
那么其它的B1、C1、A1这些就是不合法的。
那么就是3!/ 3!
就是只有一种排列是合法的。
所以样例三的答案是9! / (3! * 3! * 3!) * 4
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <assert.h>
#define IOS ios::sync_with_stdio(false)
using namespace std;
#define inf (0x3f3f3f3f)
typedef long long int LL; #include <iostream>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <string>
const int MOD = 1e9 + ;
const int maxn = 1e3 + ;
vector<int>pos;
vector<int>a;
LL quick_pow(LL a, LL b, LL MOD) { //求解 a^b%MOD的值
LL base = a % MOD;
LL ans = ; //相乘,所以这里是1
while (b) {
if (b & ) {
ans = (ans * base) % MOD; //如果这里是很大的数据,就要用quick_mul
}
base = (base * base) % MOD; //notice。注意这里,每次的base是自己base倍
b >>= ;
}
return ans;
}
LL A[maxn];
bool is[maxn];
void work() {
A[] = ;
for (int i = ; i <= maxn - ; ++i) {
A[i] = A[i - ] * i % MOD;
}
int n, m;
cin >> n >> m;
a.push_back();
for (int i = ; i <= m; ++i) {
int x;
cin >> x;
a.push_back(x);
}
a.push_back(n + );
sort(a.begin(), a.end());
// for (int i = 0; i < a.size(); ++i) {
// cout << a[i] << " ";
// }
// cout << endl;
for (int i = ; i < a.size(); ++i) {
if (a[i] - a[i - ] - == ) continue;
pos.push_back(a[i] - a[i - ] - );
if (a[i] != n + && a[i - ] != ) {
is[pos.size() - ] = true;
}
}
// for (int i = 0; i < pos.size(); ++i) {
// cout << pos[i] << " ";
// }
// cout << endl;
LL add = ;
for (int i = ; i < pos.size(); ++i) {
if (!is[i]) continue;
// cout << "fff" << endl;
add = add * quick_pow(, pos[i] - , MOD) % MOD;
}
LL sum = , haha = ;
for (int i = ; i < pos.size(); ++i) {
sum += pos[i];
haha = haha * A[pos[i]] % MOD;
}
LL ans = A[sum] * quick_pow(haha, MOD - , MOD) % MOD;
ans = ans * add % MOD;
cout << ans << endl;
} int main() {
#ifdef local
freopen("data.txt", "r", stdin);
// freopen("data.txt", "w", stdout);
#endif
work();
return ;
}
C. Shaass and Lights 组合数学的更多相关文章
- CF294C Shaass and Lights(排列组合)
题目描述 There are n n n lights aligned in a row. These lights are numbered 1 1 1 to n n n from left to ...
- CF294C Shaass and Lights
题目大意: 有n盏灯,(0<=n<=1000),有m盏已经点亮,每次只能点亮与已经点亮的灯相邻的灯,求总方案数,答案对1e9+7取模 第一行:两个整数n,m表示灯的总数和已点亮的灯的数目 ...
- 【Cf #178 A】Shaass and Lights(组合数)
考虑两个灯之间的暗灯,能从左边或右边点亮两种顺序,而最左端或最右端只有一种点亮顺序. 先不考虑点灯顺序,总共有n - m个灯要点亮,对于连续的一段暗灯,他们在总的点灯顺序中的是等价的,于是问题就可以抽 ...
- OUC_OptKernel_oshixiaoxiliu_好题推荐
poj1112 Team Them Up! 补图二分图+dp记录路径codeforces 256A Almost Arithmetical Progression dp或暴力 dp[i][j] = d ...
- Codeforces Round #178 (Div. 2)
A. Shaass and Oskols 模拟. B. Shaass and Bookshelf 二分厚度. 对于厚度相同的书本,宽度竖着放显然更优. 宽度只有两种,所以枚举其中一种的个数,另一种的个 ...
- 组合数学第一发 hdu 2451 Simple Addition Expression
hdu 2451 Simple Addition Expression Problem Description A luxury yacht with 100 passengers on board ...
- HDOJ 4770 Lights Against Dudely
状压+暴力搜索 Lights Against Dudely Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K ...
- [我给Unity官方视频教程做中文字幕]beginner Graphics – Lessons系列之灯光介绍Lights
[我给Unity官方视频教程做中文字幕]beginner Graphics – Lessons系列之灯光介绍Lights 既上一篇分享了中文字幕的摄像机介绍Cameras后,本篇分享一下第2个已完工的 ...
- poj 3734 Blocks 快速幂+费马小定理+组合数学
题目链接 题意:有一排砖,可以染红蓝绿黄四种不同的颜色,要求红和绿两种颜色砖的个数都是偶数,问一共有多少种方案,结果对10007取余. 题解:刚看这道题第一感觉是组合数学,正向推了一会还没等推出来队友 ...
随机推荐
- WinForm中TreeView控件实现鼠标拖动节点(可实现同级节点位置互换,或拖到目标子节点)
;//1:不同级, 不为1:拖同级 private void treeView1_ItemDrag(object sender, ItemDragEventArgs e) { if (e.Button ...
- 转载:ActiveMQ的可靠性机制
1.JMS消息确认机制 JMS消息只有在被确认之后,才认为已经被成功地消费了.消息的成功消费通常包含三个阶段:客户接收消息.客户处理消息和消息被确认.在事务性会话中,当一个事务被提交的时候,确认自动发 ...
- http://www.cnblogs.com/nullcnb/p/3653262.html
alert(hasPrototypeProperty(person,"name")); //false 来自原型 person1.name="mywei"; a ...
- AES加密算法实现
AES算法是一种对称加密算法,是美国国家标准技术研究所NIST旨在取代DES的21世纪的加密标准. 下文实例中,密钥采用了直接写死的方式,实际使用中可以配合RSA加密算法加密密钥,从而达到更好的安全效 ...
- CentOS 7虚拟机下模拟实现nginx负载均衡
以CentOS 7为例,我们模拟实现nginx来处理静态资源,apache来处理php 1.首先我们来安装nginx # wget http://nginx.org/packages/centos/ ...
- 古诗词api,诗词接口,诗词api,中国诗词
服务商:api.getlove.cn 分类:诗词 更新时间:2016-03 如果接口不满足您的要求,您可以联系qq:2265658022购买完整的数据库 免费apikey:56eab527a0facb ...
- Xenko基础API笔记3- Pointers指针设备屏幕上点对应的手指触摸。
样本这里是一个简单的示例程序,跟踪目前在屏幕上的指针和打印他们的位置.访问输入字段,类继承自@ SiliconStudio.Xenko.脚本的类. public override async Task ...
- linux arch目录下处理器体系架构介绍
alpha 处理器Alpha 处理器最早由美国DEC 公司设计制造,在Compaq (康柏)公司收购DEC 之后,Alpha 处理器继续得到发展,并且应用于许多高档的Compaq 服务器上,HP (惠 ...
- Life cycle of plist in Lockdown changes dramatically in iOS 10
We could take advantage of plist to bypass Trust Relationship so as to extract data from a iDevice. ...
- 用PHP向mysql添加数据
<?php $name=$_POST['name']; $gender = $_POST['gender']; $age=$_POST['age']; #连接到数据库 $link = mysql ...