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

思路:枚举这个字符串中的所有'('左括号,它左边的所有'('左括号的个数为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. gridcontrol中LayoutView层叠图片效果

    1.效果图 2.如上图效果,为比较常见的一种需求,一堆物品图片.有时候需要给不同物品标记,图中左上角就是一张标记性图片.在devexpress里面实现起来也比较容易. 3.部分代码: class Pi ...

  2. 理解WEB API网关

    *:first-child { margin-top: 0 !important; } body>*:last-child { margin-bottom: 0 !important; } /* ...

  3. JSP中三种弹出对话框的用法《转》

    对话框有三种 1:只是提醒,不能对脚本产生任何改变: 2:一般用于确认,返回 true 或者 false ,所以可以轻松用于 if...else...判断 3: 一个带输入的对话框,可以返回用户填入的 ...

  4. JavaScript:void(0);的作用

    JavaScript中void是一个操作符,该操作符指定要计算一个表达式但是不返回值. void 操作符用法格式如下: 1. javascript:void (expression) 2. javas ...

  5. JavaWeb之MVC模式

    一.什么是MVC设计模式? MVC模式(Model-View-Controller)是软件工程中的一种软件架构模式,把软件系统分为三个基本部分:模型(Model).视图(View)和控制器(Contr ...

  6. 深入理解 JavaScript 异步系列(3)—— ES6 中的 Promise

    第一部分,Promise 加入 ES6 标准 原文地址 http://www.cnblogs.com/wangfupeng1988/p/6515855.html 未经作者允许不得转载! 从 jquer ...

  7. 如何更新 OpenStack 组件?- 每天5分钟玩转 OpenStack(161)

    这是 OpenStack 实施经验分享系列的第 11 篇. 本节教大家更新 OpenStack 组件的方法.请注意,是更新(Update)而不是升级(Upgrade).更新是给组件打补丁,版本不变:而 ...

  8. CSS揭秘 技巧(五):条纹背景

    条纹背景 https://github.com/FannieGirl/ifannie/问题:条纹背景 在设觉设计中无处不在,我们真的可以用css 创建图案吗? 这一章相对还是比较复杂的哦!一起get. ...

  9. JAVA-FTP批量大文件传输

    FTP的具体使用      FTP是一种网络协议,用于进行不同服务器主机之间的文件传输,或者简单地说两台不同IP的机器之间的文件传输.在java中我们什么时候需要用到FTP文件传输呢?比如两台服务器的 ...

  10. .NET获取客户端的操作系统、IP地址、浏览器版本

    获取客户端的操作系统: #region 获取操作系统版本号 /// <summary> /// 获取操作系统版本号 /// </summary> /// <returns ...