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

先不考虑点灯顺序,总共有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. 使用tensorflow进行mnist数字识别【模型训练+预测+模型保存+模型恢复】

      import sys,os sys.path.append(os.pardir) import numpy as np from tensorflow.examples.tutorials.mni ...

  2. HTML基础范例

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  3. phpcmsv9广告版位调用方法

    <div class="ya"> <?php // pc:get 使用sql语句获取指定条件的广告版位! ?> {pc:get sql="SELE ...

  4. PHP处理表单数据的一个安全回顾(记录教训)

    曾经看过一个安全文章中写过这么一条 表单输入数据要做 htmlspecialchars_decode 表单输出数据要做htmlspecialchars 当时还不是很理解为什么,自己也没遇到问题,所以就 ...

  5. 使用git-premit时的问题

    package.json 相关配置如下 { "scripts": { "lint": "eslint pages/* component/* --fi ...

  6. [ c++] cmake 编译时 undefined reference to `std::cout' 错误的解决方案

    cmake ..  和 make 之后,出现如下错误 Linking CXX executable ../../../bin/ModuleTest CMakeFiles/ModuleTest.dir/ ...

  7. Notes of Daily Scrum Meeting(11.6 and 11.7)

    Notes of Daily Scrum Meeting(11.6 and 11.7) 因为七号星期五是放假的第一天,好几名队员要么是出去玩,要么是回家了,所以我们讨论之后在七号没有开始代码的编写, ...

  8. YQCB冲刺周第四天

    上图站立会议 任务看板: 今天的任务:做登录身份的验证,区别普通用户和超级管理员 遇到的困难:中文乱码问题

  9. 第二阶段Sprint冲刺会议10

    进展:把所有功能整合到主界面,结果导致视频只能播放不能录制,闹钟加不进去,导致闹钟功能差点不能用,放弃整合.

  10. 在visual studio中查看源代码

    地址:https://docs.microsoft.com/zh-cn/visualstudio/ide/go-to-and-peek-definition?view=vs-2017 在 Visual ...