Codeforces 380D Sereja and Cinema (看题解)
首先我们可以发现除了第一个人, 其他人都会坐在已入坐人的旁边。
难点在于计算方案数。。 我们可以从外往里把确定的人用组合数算上去,然后缩小范围。
- #include<bits/stdc++.h>
- #define LL long long
- #define LD long double
- #define fi first
- #define se second
- #define mk make_pair
- #define PLL pair<LL, LL>
- #define PLI pair<LL, int>
- #define PII pair<int, int>
- #define SZ(x) ((int)x.size())
- #define ull unsigned long long
- using namespace std;
- const int N = 1e5 + ;
- const int inf = 0x3f3f3f3f;
- const LL INF = 0x3f3f3f3f3f3f3f3f;
- const int mod = 1e9 + ;
- const double eps = 1e-;
- const double PI = acos(-);
- template<class T, class S> inline void add(T& a, S b) {a += b; if(a >= mod) a -= mod;}
- template<class T, class S> inline void sub(T& a, S b) {a -= b; if(a < ) a += mod;}
- template<class T, class S> inline bool chkmax(T& a, S b) {return a < b ? a = b, true : false;}
- template<class T, class S> inline bool chkmin(T& a, S b) {return a > b ? a = b, true : false;}
- int power(int a, int b) {
- int ans = ;
- while(b) {
- if(b & ) ans = 1LL * ans * a % mod;
- a = 1LL * a * a % mod; b >>= ;
- }
- return ans;
- }
- int inv[N], Finv[N], F[N];
- void init() {
- inv[] = F[] = Finv[] = ;
- for(int i = ; i < N; i++) inv[i] = 1LL * (mod - mod / i) * inv[mod % i] % mod;
- for(int i = ; i < N; i++) F[i] = 1LL * F[i - ] * i % mod;
- for(int i = ; i < N; i++) Finv[i] = 1LL * Finv[i - ] * inv[i] % mod;
- }
- int comb(int n, int m) {
- if(n < m || n < ) return ;
- return 1LL * F[n] * Finv[m] % mod * Finv[n - m] % mod;
- }
- int n, a[N], prefix[N];
- int solve(int L, int R) {
- if(prefix[L - ] == prefix[R]) return power(, R - L);
- int p, q;
- for(p = L; p <= R; p++) if(a[p] != ) break;
- for(q = R; q >= L; q--) if(a[q] != ) break;
- if(p == q && a[p] == ) return comb(R - L, p - L);
- int ans = ;
- if(a[p] >= a[q]) {
- int L2 = p, R2 = L2 + a[p] - ;
- if(R2 >= q && R2 <= R) add(ans, 1LL * solve(L2 + , R2) * comb(R - L - R2 + L2, L2 - L) % mod);
- }
- if(a[q] >= a[p]) {
- int R2 = q, L2 = R2 - a[q] + ;
- if(L2 >= L && L2 <= p) add(ans, 1LL * solve(L2, R2 - ) * comb(R - L - R2 + L2, L2 - L) % mod);
- }
- return ans;
- }
- int main() {
- init();
- scanf("%d", &n);
- for(int i = ; i <= n; i++) scanf("%d", &a[i]);
- for(int i = ; i <= n; i++) prefix[i] = prefix[i - ] + (a[i] != );
- printf("%d\n", solve(, n));
- return ;
- }
- /*
- */
Codeforces 380D Sereja and Cinema (看题解)的更多相关文章
- Codeforces 1017F The Neutral Zone (看题解)
这题一看就筛质数就好啦, 可是这怎么筛啊, 一看题解, 怎么会有这么骚的操作. #include<bits/stdc++.h> #define LL long long #define f ...
- Codeforces 513E2 Subarray Cuts dp (看题解)
我们肯定要一大一小间隔开来所以 把式子拆出来就是类似这样的形式 s1 - 2 * s2 + 2 * s3 + ...... + sn 然后把状态开成四个, 分别表示在顶部, 在底部, 在顶部到底部的中 ...
- Codeforces 822E Liar dp + SA (看题解)
Liar 刚开始感觉只要开个dp[ i ][ j ][ 0 / 1 ]表示处理了s的前 i 个用了 k 段, i 是否是最后一段的最后一个字符 的 t串最长匹配长度, 然后wa24, 就gg了.感觉这 ...
- Codeforces 196E Opening Portals MST (看题解)
Opening Portals 我们先考虑如果所有点都是特殊点, 那么就是对整个图求个MST. 想在如果不是所有点是特殊点的话, 我们能不能也 转换成求MST的问题呢? 相当于我们把特殊点扣出来, 然 ...
- Codeforces 725E Too Much Money (看题解)
Too Much Money 最关键的一点就是这个贪心可以在sqrt(n)级别算出答案. 因为最多有sqrt(n)个不同的数值加入. 我们可以发现最优肯定加入一个. 然后维护一个当前可以取的最大值, ...
- Codeforces 750E New Year and Old Subsequence 线段树 + dp (看题解)
New Year and Old Subsequence 第一感觉是离线之后分治求dp, 但是感觉如果要把左边的dp值和右边的dp值合起来, 感觉很麻烦而且时间复杂度不怎么对.. 然后就gun取看题解 ...
- codeforces 425C Sereja and Two Sequences(DP)
题意读了好久才读懂....不知道怎么翻译好~~请自便~~~ http://codeforces.com/problemset/problem/425/C 看懂之后纠结好久...不会做...仍然是看题解 ...
- Codeforces 547C/548E - Mike and Foam 题解
目录 Codeforces 547C/548E - Mike and Foam 题解 前置芝士 - 容斥原理 题意 想法(口胡) 做法 程序 感谢 Codeforces 547C/548E - Mik ...
- Codeforces Round #668 (Div. 2)A-C题解
A. Permutation Forgery 题目:http://codeforces.com/contest/1405/problem/A 题解:这道题初看有点吓人,一开始居然想到要用全排序,没错我 ...
随机推荐
- HBase的replication原理及部署
一.hbase replication原理 hbase 的复制方式是 master-push 方式,即主集群推的方式,主要是因为每个rs都有自己的WAL. 一个master集群可以复制给多个从集群,复 ...
- 分布式服务管理框架 ZooKeeper
核心功能 统一命名服务(Name Service) 通过有层次的目录结构产生唯一的名称,同时可以将名称关联到特定资源 配置管理(Configuration Management) ...
- [C][代码实例]交换指向常量的二级指针的位置
#include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> ...
- 异步io模块
'''客户端''' import socket,select #####进行封装,将socket对象和要返回的url,和回调函数进行一下封装 class Httprequest(): def __in ...
- GridView的stretchMode属性
stretchMode属性值的作用是设置GridView中的条目以什么缩放模式去填充剩余空间.参数stretchMode 可选值为:none,spacingWidth,columnWidth, spa ...
- flask 面试题
1,什么是Flask,有什么优点?概念解释Flask是一个Web框架,就是提供一个工具,库和技术来允许你构建一个Web应用程序.这个Web应用程序可以是一些Web页面,博客,wiki,基于Web的日里 ...
- 微信小程序简单介绍 一
一 组件及api网址: 组件 :https://developers.weixin.qq.com/miniprogram/dev/component/view.html api:https://dev ...
- SpringMVC文件下载与JSON格式
点击查看上一章 现在JSON这种数据格式是被使用的非常的广泛的,SpringMVC作为目前最受欢迎的框架,它对JSON这种数据格式提供了非常友好的支持,可以说是简单到爆. 在我们SpringMVC中只 ...
- noip 2018.10.14 模拟赛 砍树
数学问题... 根据题意,有: 移项,整理,得: 记 于是 那么 可以看到,最多只会有2*个取值(显而易见) 于是对应的,可能产生效果的d也只会有个,于是我们把他们找出来,扔进一个数组里然后排序,去重 ...
- flower
问题 D: flower 时间限制: 1 Sec 内存限制: 128 MB 题目描述 又是一年教师节,有n个小朋友打算去看望花老师.去看花老师当然要买花咯,不过某些土(xue)豪(ba)买了太多的花 ...