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取余. 题解:刚看这道题第一感觉是组合数学,正向推了一会还没等推出来队友 ...
随机推荐
- delphi.指针.PChar
此文是delphi.指针.应用姊妹篇,想细化一下PChar应用,所以有了此文. 注意: 1:此文讲的是PChar与字符串相关操作,其它方法暂不多讲. 2:由于D分开Ansi/Unicode的两种完全不 ...
- JVM & Server & Connector & Context Relationship
- iisnode托管node
1.官方下载iisnode https://github.com/tjanczuk/iisnode 2.安装完成后在IIS中可见
- JAVA IO 学习
Java流的分类 1.输入/输出流 输入流:只能向其读数据,不能写. 输出流:只能向其写数据,不能读. 所谓的输入输出都是相对应用程序而言的. 2.字节流/字符流 单位不同,字节流操作8位,字符流操作 ...
- clientTop、offsetTop和scrollTop的区分
页可见区域宽: document.body.clientWidth; 网页可见区域高: document.body.clientHeight; 网页可见区域宽: document.body.offse ...
- mybatiGenerator
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE generatorConfiguratio ...
- SQL Server提高事务复制效率优化(二)快照初始化优化
测试数据表量1500w+,使用初始化默认的快照代理参数,复制的三个过程包括快照初始化,订阅初始化和数据修改复制,主要对快照代理.分发代理.日志读取代理分别作了参数优化,并给出优化前后的对照实验测试. ...
- 字符串怎么换行 || 字符串中使用单引号时应该怎么写 || 保留两位小数 || 数字0在if中的意思是false || 什么情况下会会报undefined || null和undefined的区别 ||
换行的字符串 "This string\nhas two lines" 字符串中使用单引号时应该怎么写 'You\'re right, it can\'t be a quote' ...
- 标准bootstrap html 页面
<!DOCTYPE html><html lang="zh-cn"><head> <meta charset="utf-8&qu ...
- C# 生成表格代碼
public ActionResult btnExport(ReportViewModel model) { //接收需要导出的数据 L ...