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 组合数学的更多相关文章

  1. 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 ...

  2. CF294C Shaass and Lights

    题目大意: 有n盏灯,(0<=n<=1000),有m盏已经点亮,每次只能点亮与已经点亮的灯相邻的灯,求总方案数,答案对1e9+7取模 第一行:两个整数n,m表示灯的总数和已点亮的灯的数目 ...

  3. 【Cf #178 A】Shaass and Lights(组合数)

    考虑两个灯之间的暗灯,能从左边或右边点亮两种顺序,而最左端或最右端只有一种点亮顺序. 先不考虑点灯顺序,总共有n - m个灯要点亮,对于连续的一段暗灯,他们在总的点灯顺序中的是等价的,于是问题就可以抽 ...

  4. OUC_OptKernel_oshixiaoxiliu_好题推荐

    poj1112 Team Them Up! 补图二分图+dp记录路径codeforces 256A Almost Arithmetical Progression dp或暴力 dp[i][j] = d ...

  5. Codeforces Round #178 (Div. 2)

    A. Shaass and Oskols 模拟. B. Shaass and Bookshelf 二分厚度. 对于厚度相同的书本,宽度竖着放显然更优. 宽度只有两种,所以枚举其中一种的个数,另一种的个 ...

  6. 组合数学第一发 hdu 2451 Simple Addition Expression

    hdu 2451 Simple Addition Expression Problem Description A luxury yacht with 100 passengers on board ...

  7. HDOJ 4770 Lights Against Dudely

    状压+暴力搜索 Lights Against Dudely Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K ...

  8. [我给Unity官方视频教程做中文字幕]beginner Graphics – Lessons系列之灯光介绍Lights

    [我给Unity官方视频教程做中文字幕]beginner Graphics – Lessons系列之灯光介绍Lights 既上一篇分享了中文字幕的摄像机介绍Cameras后,本篇分享一下第2个已完工的 ...

  9. poj 3734 Blocks 快速幂+费马小定理+组合数学

    题目链接 题意:有一排砖,可以染红蓝绿黄四种不同的颜色,要求红和绿两种颜色砖的个数都是偶数,问一共有多少种方案,结果对10007取余. 题解:刚看这道题第一感觉是组合数学,正向推了一会还没等推出来队友 ...

随机推荐

  1. WinForm控件TreeView 只部分节点显示 CheckBox

    WinForm控件TreeView 只部分节点显示  CheckBox 用过asp.net的应该知道,要在treeview中实现上述功能可以使用ShowCheckBox 属性指定那些节点显示check ...

  2. Oracle分区表!

    Oracle 数据库分区表的创建和操作 摘要:在大量业务数据处理的项目中,可以考虑使用分区表来提高应用系统的性能并方便数据管理,本文详细介绍了分区表的使用. 在大型的企业应用或企业级的数据库应用中,要 ...

  3. pip China

    建个文件 ~/.pip/pip.conf, 内容如下 [global] index-url = http://b.pypi.python.org/simple [install] use-mirror ...

  4. JAVA IO 学习

    Java流的分类 1.输入/输出流 输入流:只能向其读数据,不能写. 输出流:只能向其写数据,不能读. 所谓的输入输出都是相对应用程序而言的. 2.字节流/字符流 单位不同,字节流操作8位,字符流操作 ...

  5. Robotium怎样判断测试结果

    Robotium判断测试结果的方法主要有三类:assert.is.search.assert方法除了Robotium API,还有Junit中的所有断言方法,Junit的断言方法下篇详解. void ...

  6. 浅谈数位DP

    在了解数位dp之前,先来看一个问题: 例1.求a~b中不包含49的数的个数. 0 < a.b < 2*10^9 注意到n的数据范围非常大,暴力求解是不可能的,考虑dp,如果直接记录下数字, ...

  7. 二模12day2解题报告

    T1.笨笨玩糖果(sugar) 有n颗糖,两个人轮流取质数颗糖,先取不了的(0或1)为输,求先手能否必胜,能,输出最少几步肯定能赢:不能,输出-1. 一开始天真的写了一个dp,f[i]表示i颗糖最少取 ...

  8. PIC32MZ tutorial -- Core Timer

    Core Timer is a very popular feature of PIC32 since it is a piece of the MIPS M4K core itself and is ...

  9. xampp windows版本安装后无法使用大文件下载的解决办法

    找到httpd.conf 在<Directory "C:/xampp/htdocs"> </Directory>添加EnableSendfile On

  10. Hibernate的查询方式总结

    Hibernate的查询方式大体有三种,分别是HQL QBC和SQL三种.在网上查阅一一些资料,做了一个简单的总结. 1. SQL sql 是面向数据库表查询,from 后面跟的是表名,where 后 ...