Codeforces 785 D. Anton and School - 2
题目链接:http://codeforces.com/contest/785/problem/D
我们可以枚举分界点,易知分界点左边和右边分别有多少个左括号和右括号,为了不计算重复我们强制要求选择分界点左边的那一个左括号(也就是说如果枚举的这个分界点的左边这个位置没有左括号就强制这个位置不产生贡献)。
对于一个分界点我们记它左边有$le[x]$个左括号,右边有$ri[x]$个右括号。
${Ans=\sum_{x=1}^{n-1} \sum _{i=1}^{min(le[x]-1,ri[x]])}C(le[x]-1,i)*C(r[x],i)}$
${=\sum_{x=1}^{n-1} C(le[x]-1+ri[x],ri[x])}$
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<cstdlib>
#include<cmath>
#include<cstring>
using namespace std;
#define maxn 1000010
#define llg long long
#define yyj(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout);
#define md 1000000007
llg n,m,le[maxn],ri[maxn],inv[maxn],fac[maxn]; char c[maxn]; llg ksm(llg a,llg b)
{
llg ans=;
while (b)
{
if (b&) ans*=a,ans%=md;
a*=a,a%=md;
b/=;
}
return ans;
} llg C(llg N,llg M)
{
if (M==) return ;
return fac[N]*inv[M]%md*inv[N-M]%md;
} int main()
{
yyj("D");
scanf("%s",c+);
n=strlen(c+);
llg p=;
for (llg i=;i<=n;i++)
{
if (c[i]=='(') p++;
le[i+]=p;
}
p=;
for (llg i=n;i>=;i--)
{
if (c[i]==')') p++;
ri[i]=p;
}
fac[]=;
llg ans=;
for (llg i=;i<=n*+;i++)
fac[i]=fac[i-]*i%md,inv[i]=ksm(fac[i],md-);
// fac[0]=0;
for (llg i=;i<=n;i++)
if (le[i] && ri[i] && c[i-]=='(')
ans+=C(le[i]+ri[i]-,ri[i]-),ans%=md;
cout<<ans;
return ;
}
Codeforces 785 D. Anton and School - 2的更多相关文章
- Codeforces 785 D.Anton and School - 2(组合数处理)
Codeforces 785 D.Anton and School - 2 题目大意:从一串由"(",")"组成的字符串中,找出有多少个子序列满足:序列长度为偶 ...
- Codeforces 785 E. Anton and Permutation(分块,树状数组)
Codeforces 785 E. Anton and Permutation 题目大意:给出n,q.n代表有一个元素从1到n的数组(对应索引1~n),q表示有q个查询.每次查询给出两个数l,r,要求 ...
- CodeForces 785 D Anton and School - 2 范德蒙恒等式
Anton and School - 2 题解: 枚举每个左括号作为必选的. 那么方案数就应该是下面的 1 , 然后不断化简, 通过范德蒙恒等式 , 可以将其化为一个组合数. 代码: #include ...
- Codeforces 785 - A/B/C/D/E - (Undone)
链接:https://codeforces.com/contest/785 A - Anton and Polyhedrons #include<bits/stdc++.h> using ...
- 【codeforces 785E】Anton and Permutation
[题目链接]:http://codeforces.com/problemset/problem/785/E [题意] 给你一个初始序列1..n顺序 然后每次让你交换任意两个位置上面的数字; 让你实时输 ...
- 【codeforces 785D】Anton and School - 2
[题目链接]:http://codeforces.com/contest/785/problem/D [题意] 给你一个长度为n的括号序列; 让你删掉若干个括号之后,整个序列变成前x个括号为左括号,后 ...
- 【27.91%】【codeforces 734E】Anton and Tree
time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...
- 【codeforces 785C】Anton and Fairy Tale
[题目链接]:http://codeforces.com/contest/785/problem/C [题意] 容量为n的谷仓,每一天都会有m个谷子入仓(满了就视为m);第i天 会有i只鸟叼走i个谷子 ...
- 【codeforces 785B】Anton and Classes
[题目链接]:http://codeforces.com/contest/785/problem/B [题意] 给你两个时间各自能够在哪些时间段去完成; 让你选择两个时间段来完成这两件事情; 要求两段 ...
随机推荐
- 自写Jquery插件 Tab
原创文章,转载请注明出处,谢谢!https://www.cnblogs.com/GaoAnLee/p/9067017.html 每每看到别人写的Jquery插件,自己也试着学习尝试,终有结果,废话不多 ...
- react将表格动态生成视频列表【代码】【案例】
只需要创建一个表格,id为videos,react就能将这个表格转换成视频列表,并点击自动播放 index.html <!DOCTYPE html> <html> <he ...
- 流媒体协议(RTMP、RTSP、UDP、HTTP、MMS)转换小工具(RTSP转成RTMP案例展示)(转)
源: 流媒体协议(RTMP.RTSP.UDP.HTTP.MMS)转换小工具(RTSP转成RTMP案例展示)
- django 上传文件及反馈信息
from django.shortcuts import render,HttpResponse from django.views import View from Fiskars.models i ...
- linux释放页面缓存drop_caches
关于drop_caches文件:系统默认为0 在Documentation/sysctl/vm.txt中有如下描述: drop_caches Writing to this will cause th ...
- windows 10下oracle相关异常及处理方法
话说起来,不以oracle性能优化,数据库维护为主业已经有四五年了,这两年基本上以mysql为主. pl/sql登录后提示空白对话框.将ORACLE_HOME设置为oracle 11g的目录. IMP ...
- linux普通用户提权
tar通配符注入. echo 'echo "chenglee ALL=(root) NOPASSWD: ALL" > /etc/sudoers' > demo.sh e ...
- svg动态添加小人
<!DOCTYPE html> <html lang="en"> <head> <meta charset="utf-8&quo ...
- freeswitch 获取app和api帮助
通过show显示帮助命令 输出xml格式:show calls as xml 输出json格式 列出所有:show codec 解释: codec - 列出所有编码 endpoint - 列出所有en ...
- CF 1087解题报告
cf解题报告 记录一下吧 做出:T1 rating :-97 想起几个月前做不出T1还是有点小搞笑呀2333 T1 双指针+特判 T2 发现k特别小,枚举剩余系 还要判断是否是能被n整除 移项发现可以 ...