题意:给你一个由'('和')'组成的字符串,问你有多少个子串,前半部分是由'('组成后半部分由')'组成

思路:枚举这个字符串中的所有'('左括号,它左边的所有'('左括号的个数为num1,它的右边的所有’)'右括号的个数为num2,

根据范德蒙恒等式计算得出

代码:

#include <bits/stdc++.h>
#define ll long long
#define maxn 200000
#define mod 1000000007
using namespace std; ll jc[maxn+]; void get_jc()
{
jc[]=;
for(int i=;i<=maxn;i++)
{
jc[i]=(jc[i-]*i)%mod;
}
} ll qmod(ll a,ll b)
{
ll ans=;
while(b)
{
if(b%==)
{
ans=(ans*a)%mod;
}
b=b/;
a=(a*a)%mod;
}
return ans;
} ll get_C(ll m,ll n)
{
return (jc[m]*qmod((jc[m-n]*jc[n])%mod,mod-))%mod;
} int main()
{
string data;
int num1[maxn+],num2[maxn+];
get_jc();
while(cin>>data)
{
int p=;
for(int i=;i<data.length();i++)
{
if(data[i]=='(')
{
p++;
}
num1[i]=p;
}
p=;
ll ans=;
for(int i=data.length()-;i>=;i--)
{
if(data[i]==')')
{
p++;
}
num2[i]=p;
}
for(int i=;i<data.length();i++)
{
if(data[i]=='(')
{
ans=(ans+get_C(num1[i]+num2[i]-,num2[i]-))%mod;
}
}
cout<<ans<<endl;
}
return ;
}

CF #404 (Div. 2) D. Anton and School - 2 (数论+范德蒙恒等式)的更多相关文章

  1. CF #404 (Div. 2) B. Anton and Classes (贪心)

    题意:有一个小朋友,即喜欢下象棋,还喜欢编程,于是他打算上这两种课的兴趣班,这两种课有着不同的上课时间,他想让两堂课之间的休息时间最多,问最大时间是多少 思路:看到这道题的第一反应就是贪心,于是用结构 ...

  2. Codeforces Round #404 (Div. 2) D. Anton and School - 2 数学

    D. Anton and School - 2 题目连接: http://codeforces.com/contest/785/problem/D Description As you probabl ...

  3. Codeforces Round #404 (Div. 2) A,B,C,D,E 暴力,暴力,二分,范德蒙恒等式,树状数组+分块

    题目链接:http://codeforces.com/contest/785 A. Anton and Polyhedrons time limit per test 2 seconds memory ...

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

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

  5. Codeforces Round #404 (Div. 2) C. Anton and Fairy Tale 二分

    C. Anton and Fairy Tale 题目连接: http://codeforces.com/contest/785/problem/C Description Anton likes to ...

  6. Codeforces Round #404 (Div. 2) B. Anton and Classes 水题

    B. Anton and Classes 题目连接: http://codeforces.com/contest/785/problem/B Description Anton likes to pl ...

  7. Codeforces Round #404 (Div. 2) A - Anton and Polyhedrons 水题

    A - Anton and Polyhedrons 题目连接: http://codeforces.com/contest/785/problem/A Description Anton's favo ...

  8. Codeforces Round #404 (Div. 2) E. Anton and Permutation(树状数组套主席树 求出指定数的排名)

    E. Anton and Permutation time limit per test 4 seconds memory limit per test 512 megabytes input sta ...

  9. Codeforces Round #404 (Div. 2) D. Anton and School - 2

    题目链接 转自 给你一个字符串问你能构造多少RSBS. #include<bits/stdc++.h> #define LL long long #define fi first #def ...

随机推荐

  1. Two analytical 2d line intersection in OpenCASCADE

    Two analytical 2d line intersection in OpenCASCADE eryar@163.com Abstract. OpenCASCADE geometric too ...

  2. Android系统--Binder系统具体框架分析(二)Binder驱动情景分析

    Android系统--Binder系统具体框架分析(二)Binder驱动情景分析 1. Binder驱动情景分析 1.1 进程间通信三要素 源 目的:handle表示"服务",即向 ...

  3. H5缓存-Manifest

    在app中更新h5页面一直有缓存问题.默认什么都不做的情况下,app有一定的空间缓存页面.一开始更新之后会马上加载,等到app缓存空间上来之后更新就无法下载了.安卓能够清理缓存空间,ios就只能卸载重 ...

  4. BASH SHELL not a valid identifier

    解决BASH SHELL脚本报错 ‘: not a valid identifier当在shell编辑脚本时,运行时出现了" ‘: not a valid identifier " ...

  5. javascript 常用api

    常用API合集 来源于:https://www.kancloud.cn/dennis/tgjavascript/241852 一.节点 1.1 节点属性 Node.nodeName //返回节点名称, ...

  6. lxd-启动篇分析

    lxd是什么:lxd是基于lxc构筑的容器管理进程,提供镜像,网络,存储,以及容器的能力,对外暴漏restfull API.其与docker的区别是docker更切近与app container,以应 ...

  7. 电器ERP行业案例——环力科技

    环力科技ERP案例 企业简介 [规模] 环力公司始建于1992年,是一家专业生产电子压力控制器.水泵压力控制器.气泵压力控制器.电泵浮球控制器.全自动水泵及其它配套产品研究.开发.生产.销售为一体的专 ...

  8. CSS中@import与link的具体区别

    我们知道在网页中引用外部CSS有两种方式:@import和link 我们也经常听到有人说要使用link来引入CSS更好,但是你知道为什么吗? 继续往下看 link:link就是把外部CSS与网页连接起 ...

  9. smarty fetch方法

    fetch   取得输出的内容 返回一个模板输出的内容(HTML代码),而不是直接显示出来,需要指定一个合法的模 板资源的类型和路径.你还可以通过 第二个可选参数指定一个缓存号,相关的信息可以查看缓存 ...

  10. ACM 组合数

    组合数 时间限制:3000 ms  |  内存限制:65535 KB 难度:3   描述 找出从自然数1.2.... .n(0<n<10)中任取r(0<r<=n)个数的所有组合 ...