【Cf #178 A】Shaass and Lights(组合数)
2018-07-11 20:57
302 查看
#include <cstdio> #include <algorithm> typedef long long LL; const int N = 1005, MOD = 1e9 + 7; int n, m, a , d , pw2 , fac ; int Pow(int x, int b, int re = 1) { for (; b; b >>= 1, x = (LL) x * x % MOD) if (b & 1) re = (LL) re * x % MOD; return re; } int main() { scanf("%d%d", &n, &m); pw2[0] = fac[0] = 1; for (int i = 1; i <= m; ++i) { scanf("%d", &a[i]); } for (int i = 1; i <= n; ++i) { pw2[i] = pw2[i - 1] * 2 % MOD; fac[i] = (LL) fac[i - 1] * i % MOD; } std::sort(a + 1, a + 1 + m); int ans = fac[n - m]; for (int i = 1; i < m; ++i) { int d = a[i + 1] - a[i] - 1; if (d == 0) continue; ans = (LL) ans * Pow(fac[d], MOD - 2) % MOD; ans = (LL) ans * pw2[d - 1] % MOD; } if (a[1] > 1) ans = (LL) ans * Pow(fac[a[1] - 1], MOD - 2) % MOD; if (a[m] < n) ans = (LL) ans * Pow(fac[n - a[m]], MOD - 2) % MOD; printf("%d\n", ans); return 0; }View Code
相关文章推荐
- Codeforces Round #178 (Div. 2) C. Shaass and Lights
- C. Shaass and Lights
- CodeForces 294C - Shaass and Lights 统计
- 排列组合 Shaass and Lights:CodeForces - 294C
- Codeforces Round #178 (Div. 2) C. Shaass and Lights 【组合数学】
- 第十一届湖南省省赛 - Internet of Lights and Switches(二分 + 位运算)
- Codeforces 621B Wet Shark and Bishops(判定对角线点+组合数统计)
- CF689E:Mike and Geometry Problem(组合数)
- XNA--camera, lights and effects
- C r and n(组合数)
- NGUI Example5 演示示例评论– lights and Refraction
- OpenGL学习脚印:光源类型和使用多个光源(Light source and multiple lights)
- UVA 10375 Choose and divide(组合数运算)
- [CF 294D]Shaass and Painter Robot解题报告
- Codeforces Round #178 (Div. 2) B .Shaass and Bookshelf
- C r and n(组合数)
- Kyoya and Colored Balls(组合数)
- CUIT ACM Personal Training 11.27(FM)E - Shaass and Oskols
- Internet of Lights and Switches(MAP记录+二分) 2015年湖南省赛第 I 题
- Internet of Lights and Switches 湖南2015省赛I题 (异或+map)