考虑两个灯之间的暗灯,能从左边或右边点亮两种顺序,而最左端或最右端只有一种点亮顺序。

先不考虑点灯顺序,总共有n - m个灯要点亮,对于连续的一段暗灯,他们在总的点灯顺序中的是等价的,于是问题就可以抽象成有重复元素的组合数:

$ C = \frac{ (n - m)! }{ \prod_{i = 1}^{k} \, x_{i} ! }  $ 。

在考虑一段连续的暗灯内部的点灯顺序,只要让答案乘上 $ 2 ^ {len - 1} $ 即可。

$ \bigodot $ 技巧&套路:

  • 组合数应用的模型,组合数的运用
 #include <cstdio>
#include <algorithm> typedef long long LL;
const int N = , MOD = 1e9 + ; int n, m, a[N], d[N], pw2[N], fac[N]; int Pow(int x, int b, int re = ) {
for (; b; b >>= , x = (LL) x * x % MOD) if (b & ) re = (LL) re * x % MOD;
return re;
} int main() {
scanf("%d%d", &n, &m);
pw2[] = fac[] = ;
for (int i = ; i <= m; ++i) {
scanf("%d", &a[i]);
}
for (int i = ; i <= n; ++i) {
pw2[i] = pw2[i - ] * % MOD;
fac[i] = (LL) fac[i - ] * i % MOD;
}
std::sort(a + , a + + m); int ans = fac[n - m];
for (int i = ; i < m; ++i) {
int d = a[i + ] - a[i] - ;
if (d == ) continue;
ans = (LL) ans * Pow(fac[d], MOD - ) % MOD;
ans = (LL) ans * pw2[d - ] % MOD;
}
if (a[] > ) ans = (LL) ans * Pow(fac[a[] - ], MOD - ) % MOD;
if (a[m] < n) ans = (LL) ans * Pow(fac[n - a[m]], MOD - ) % MOD;
printf("%d\n", ans); return ;
}

【Cf #178 A】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. C. Shaass and Lights 组合数学

    http://codeforces.com/contest/294/problem/C 把那个数组n分段了,那么有两类. 1.开头和端点那些,就是只有一端在开始的,这个时候,要开完这些灯,只能循序渐进 ...

  3. CF294C Shaass and Lights

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

  4. Codeforces Round #178 (Div. 2)

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

  5. OUC_OptKernel_oshixiaoxiliu_好题推荐

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

  6. Codeforces Round #178 (Div. 2) B. Shaass and Bookshelf —— DP

    题目链接:http://codeforces.com/contest/294/problem/B B. Shaass and Bookshelf time limit per test 1 secon ...

  7. Codeforces Round #178 (Div. 2) B .Shaass and Bookshelf

    Shaass has n books. He wants to make a bookshelf for all his books. He wants the bookshelf's dimensi ...

  8. cf里的一些简单组合数题

    cf711D 成环的和不成环的要单独计算,环用双联通做的QAQ /* 所有情况-成环的情况 */ #include<bits/stdc++.h> using namespace std; ...

  9. HDOJ 4770 Lights Against Dudely

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

随机推荐

  1. C++ 学习笔记 变量和基本类型(一)

    C++ 学习笔记 一.变量和基本类型概述 类型是所有程序的基础.类型告诉我们数据代表什么意思以及可以对数据执行哪些操作. c++基本类型: 字符型 整型 浮点型 c++ 还提供了可用于自定义数据类型的 ...

  2. Swing的概述

    Swing在Java中是一个包,下面就是它的基本概述:简介: Java为了方便图形界面的实现, 专门设计了类库来满足各种各样的图形元素和用户交互事件, 该类库即为抽象窗口工具箱(Abstract Wi ...

  3. Hyperledger Fabric chaincode 开发(疑难解答)

    Q&A Q1: 使用fabric release 1.2 进行golang chaincode开发时报错: ..\..\hyperledger\fabric\vendor\github.com ...

  4. UIWebView控件中 字体大小和字体样式的修改

    修改UIWebView控件中字体的样式: NSString *htmlString = [NSString stringWithContentsOfFile:self.webPath encoding ...

  5. xlutils模块使用

    python常用模块目录 1.xlutils 实现拷贝原文件 原表格: import xlrd from xlutils.copy import copy workbook = xlrd.open_w ...

  6. Python爬虫框架Scrapy学习笔记原创

     字号 scrapy [TOC] 开始 scrapy安装 首先手动安装windows版本的Twisted https://www.lfd.uci.edu/~gohlke/pythonlibs/#twi ...

  7. Bing词典vs有道词典比对测试报告——体验篇之软件适应性

    联网情况: 在联网情况下,针对每一次查询,有道词典的反应速度明显比必应词典快得多.据我推测有以下两个原因: 有道词典有本地词库而必应词典更多依赖联网. 有道词典的服务器在国内而必应的在国外. 断网情况 ...

  8. Internet History, Technology and Security (Week5.1)

    Week5 The Transport layer is built on the Internetwork layer and is what makes our network connectio ...

  9. 关于mybatis的思考(3)——ResultMaps的使用

    ResultMap元素在mybatis中非常重要,目的是告诉mybatis将从结果集中取出的数据转换为开发者需要的对象.     UserMapping.xml <!-- selectAll操作 ...

  10. nodeJS + webStrome

    一.配置开发环境: 1.先安装node (1).访问http://nodejs.org打开安装包,正常安装,点击next即可. 为了测试是否安装成功,打开命令提示符,输入node,则进入node.js ...