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. iPad 控件 UIPopoverPresentationController 使用 iPhone可用

    UIPopoverController 在iOS9之后被废弃了,,, iOS8 新控件UIPopoverPresentationController可运用在iphone和iPad上,使用基本同 UIP ...

  2. IntelliJ IDEA 自动化工具安装并添加自动化测试框架

    IntelliJ IDEA是一个用于开发人员开发和测试人员自动化测试的测试工具,类似于eclipse. 优点:插件多自身可以携带,自身携带cucumber自动化测试框架,类似于junit一样 缺点:r ...

  3. Thinkphp源码分析系列(四)–Dispatcher类

    下面我们来分析一下Thinkphp中的url解析和路由调度类.此类主要功能是 // +--------------------------------------------------------- ...

  4. 配置Struts.xml DTD文件报错

    报错信息为: The content of element type "struts" must match "((package|include|bean|  cons ...

  5. Ubuntu更改鼠标灵敏度

    需要命令:xinput 清自行用 man xinput 查询 xinput 帮助文档 1.插入鼠标,打开终端,输入命令:xinput 查询当前已挂在设备 2.拔出鼠标,打开终端,再输入命令:xinpu ...

  6. JAVA代码热部署,在线不停服动态更新

    本地debug的时候,可以实时编译并更新代码,线上也可以不停服来动态更新类,即所说的java热部署.   JDK代理的两种方式: 1.premain方式是Java SE5开始就提供的代理方式,但其必须 ...

  7. C语言中内存操作函数

      一.malloc/calloc 名称: Malloc/calloc 功能: 动态内存分配函数 头文件: #include <stdlib.h> 函数原形: void *malloc(s ...

  8. JS定时程序,设定一个一直刷新,又时间间隔的js,读取当前的时间并显示

    <!doctype html><html><head><meta charset="utf-8"><title>无标题文 ...

  9. VBS实现定时发送邮件

    原理:建立CDO.Message对象,设置好参数后直接Send就可以了 代码如下: NameSpace = "http://schemas.microsoft.com/cdo/configu ...

  10. ASP.NET 表单验证实现浅析

    首先,自然是配置 Web.config,在 <system.web> 下设定: <authentication mode="Forms"> <form ...