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

思路:枚举这个字符串中的所有'('左括号,它左边的所有'('左括号的个数为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. Vue2.0源码阅读笔记--双向绑定实现原理

    上一篇 文章 了解了Vue.js的生命周期.这篇分析Observe Data过程,了解Vue.js的双向数据绑定实现原理. 一.实现双向绑定的做法 前端MVVM最令人激动的就是双向绑定机制了,实现双向 ...

  2. devexpress表格gridcontrol实现分组,并根据分组计算总计及平均值

    1.devexpress表格控件gridcontrol提供了强大的分组功能,你几乎不用写什么代码就可以实现一个分组功能,并且可根据分组计算总计和平均值.这里我例举了一个实现根据班级分组计算班级总人数, ...

  3. SerfJ REST

    SerfJ提供了一个MVC架构,但它不包含任何模型,其主要特点是使用控制器collerlor,通过这些collerlor管理REST请求.可帮助你开发优雅的MVC架构的应用,使用惯例重于配置的思路,无 ...

  4. ThinkPHP项目总结

    1.当你 require ThinkPHP之后,会自动在App目录下生成 common, Home, Runtime 三个文件夹. 2.输入网址 http://localhost/blog/app/i ...

  5. Caffe学习系列(一)Ubuntu16.04下搭建编译Caffe环境,并运行MNIST示例(仅CPU)

    前言: 正文: 1.安装必要依赖包: sudo apt-get install libprotobuf-dev libleveldb-dev libsnappy-dev libopencv-dev l ...

  6. 【SysML】模块定义图(BDD, Block Definition Diagram)

    一.引言 SysML中的模块定义图,英文为 “Block Definition Diagram”,简称BDD,是系统建模过程中最为常见的图之一,BDD是一种结构图,它主要对系统的结构组成以及组成元素间 ...

  7. EAS组件编辑和显示的自定义

    KDFormattedTextField kdtEntrys_returnAmount_TextField = new KDFormattedTextField(); kdtEntrys_return ...

  8. 交互神器 Facebook Origami

    最近用到了一个非常强大的工具,这是一款由 facebook 出品的原型设计软件,老规矩我们先来看一下效果.大家也可以先进去官网看看效果Origami 官网 scroll.gif swipe.gif O ...

  9. 腾讯云数据库团队:浅谈如何对MySQL内核进行深度优化

    作者介绍:简怀兵,腾讯云数据库团队高级工程师,负责腾讯云CDB内核及基础设施建设:先后供职于Thomson Reuters和YY等公司,PTimeDB作者,曾获一项发明专利:从事MySQL内核开发工作 ...

  10. 用tp框架来对数据库进行增删改

    先来看添加 使用tp框架,对数据库进行添加操作,都有哪些方法 先在Main控制器中,做个方法 运行一下,注意地址,就要输tianjia了 然后再看一下数据库,有没有添加上数据 添加成功 再来看一下这个 ...