题目链接: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的更多相关文章

  1. Codeforces 785 D.Anton and School - 2(组合数处理)

    Codeforces 785 D.Anton and School - 2 题目大意:从一串由"(",")"组成的字符串中,找出有多少个子序列满足:序列长度为偶 ...

  2. Codeforces 785 E. Anton and Permutation(分块,树状数组)

    Codeforces 785 E. Anton and Permutation 题目大意:给出n,q.n代表有一个元素从1到n的数组(对应索引1~n),q表示有q个查询.每次查询给出两个数l,r,要求 ...

  3. CodeForces 785 D Anton and School - 2 范德蒙恒等式

    Anton and School - 2 题解: 枚举每个左括号作为必选的. 那么方案数就应该是下面的 1 , 然后不断化简, 通过范德蒙恒等式 , 可以将其化为一个组合数. 代码: #include ...

  4. Codeforces 785 - A/B/C/D/E - (Undone)

    链接:https://codeforces.com/contest/785 A - Anton and Polyhedrons #include<bits/stdc++.h> using ...

  5. 【codeforces 785E】Anton and Permutation

    [题目链接]:http://codeforces.com/problemset/problem/785/E [题意] 给你一个初始序列1..n顺序 然后每次让你交换任意两个位置上面的数字; 让你实时输 ...

  6. 【codeforces 785D】Anton and School - 2

    [题目链接]:http://codeforces.com/contest/785/problem/D [题意] 给你一个长度为n的括号序列; 让你删掉若干个括号之后,整个序列变成前x个括号为左括号,后 ...

  7. 【27.91%】【codeforces 734E】Anton and Tree

    time limit per test3 seconds memory limit per test256 megabytes inputstandard input outputstandard o ...

  8. 【codeforces 785C】Anton and Fairy Tale

    [题目链接]:http://codeforces.com/contest/785/problem/C [题意] 容量为n的谷仓,每一天都会有m个谷子入仓(满了就视为m);第i天 会有i只鸟叼走i个谷子 ...

  9. 【codeforces 785B】Anton and Classes

    [题目链接]:http://codeforces.com/contest/785/problem/B [题意] 给你两个时间各自能够在哪些时间段去完成; 让你选择两个时间段来完成这两件事情; 要求两段 ...

随机推荐

  1. <转>jmeter(三)SOAP/XML-RPC Request

    本博客转载自:http://www.cnblogs.com/imyalost/category/846346.html 个人感觉不错,对jmeter讲解非常详细,担心以后找不到了,所以转发出来,留着慢 ...

  2. SQL SERVER镜像配置(包含见证服务器)

    镜像简介   重要说明:保持数据库镜像运行.如果您关闭数据库镜像,则必须执行完全备份并还原数据库以重建数据库镜像.   一. 简介 SQL SERVER 2005镜像基于日志同步,可良好实现故障转移. ...

  3. The Little Prince-12/07

    The Little Prince-12/07 "My little man, where do you come from? What is this ‘where I live,‘ of ...

  4. FFMPEG结构体分析:AVFrame(解码后的数据)

    https://blog.csdn.net/jxcr1984/article/details/52766524 本文转自: http://blog.csdn.net/leixiaohua1020/ar ...

  5. Jquery autocomplete.js输入框联想补全功能

    Jquery autocomplete.js插件下载地址:http://files.cnblogs.com/files/jinzhiming/autocomplete.rar 有两种用法,一种是直接使 ...

  6. rabbitmq集群安装与配置(故障恢复)

    0.首先按照http://www.cnblogs.com/zhjh256/p/5922562.html在至少两个节点安装好(不建议单机,没什么意义) 1.先了解rabbitmq集群架构,http:// ...

  7. 01: docker 基本使用

    1.1 docker基础 1.docker与虚拟机比较 2.docker版本 1. 社区版(Community Edition, CE) 2. 企业版(Enterprise Edition, EE) ...

  8. vue2.0之echarts使用

    1.首先下载echart依赖 npm install echarts --save备注:npm 安装报错时使用cnpm 2.全局注册 在main.js里引入echart并在vue中注册echart / ...

  9. QML常用控件

    这里的控件是显示的元素 1.Item:一切的基类 Item { Image { source: "tile.png" } Image { x: width: height: sou ...

  10. 复旦大学2016--2017学年第二学期高等代数II期末考试情况分析

    一.期末考试成绩班级前十五名 林晨(93).朱民哲(92).何陶然(91).徐钰伦(91).吴嘉诚(91).于鸿宝(91).宁盛臻(90).杨锦文(89).占文韬(88).章俊鑫(87).颜匡萱(87 ...