CF #404 (Div. 2) D. Anton and School - 2 (数论+范德蒙恒等式)
题意:给你一个由'('和')'组成的字符串,问你有多少个子串,前半部分是由'('组成后半部分由')'组成
思路:枚举这个字符串中的所有'('左括号,它左边的所有'('左括号的个数为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 (数论+范德蒙恒等式)的更多相关文章
- CF #404 (Div. 2) B. Anton and Classes (贪心)
题意:有一个小朋友,即喜欢下象棋,还喜欢编程,于是他打算上这两种课的兴趣班,这两种课有着不同的上课时间,他想让两堂课之间的休息时间最多,问最大时间是多少 思路:看到这道题的第一反应就是贪心,于是用结构 ...
- 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 ...
- 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 ...
- CodeForces 785 D Anton and School - 2 范德蒙恒等式
Anton and School - 2 题解: 枚举每个左括号作为必选的. 那么方案数就应该是下面的 1 , 然后不断化简, 通过范德蒙恒等式 , 可以将其化为一个组合数. 代码: #include ...
- 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 ...
- 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 ...
- Codeforces Round #404 (Div. 2) A - Anton and Polyhedrons 水题
A - Anton and Polyhedrons 题目连接: http://codeforces.com/contest/785/problem/A Description Anton's favo ...
- 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 ...
- Codeforces Round #404 (Div. 2) D. Anton and School - 2
题目链接 转自 给你一个字符串问你能构造多少RSBS. #include<bits/stdc++.h> #define LL long long #define fi first #def ...
随机推荐
- git合并别的分支某次提交或合并
合并别的分支某次提交 master分支上改了一个bug.提交到master分支.现在在dev分支上开发,需要把master分支上改的那个bug合过来.步骤是:先在master分支上查改那个bug的SH ...
- HTTP基础知识(二)
接着上一章的内容:HTTP基础知识(一) 二.简单的HTTP协议 1.客户端:请求访问文本或图像等资源的一端称为客户端: 服务器端:提供资源响应的一端 2.以百度为例子 这是请求头: 在起始行 ...
- Asp.net mvc 4.0 高级编程 百度云下载
Asp.net mvc 4.0 高级编程 百度云下载地址:链接:http://pan.baidu.com/s/1o6zFvOe 密码:xyss 1.基于 ASP.NET MVC4.0 + WebAPI ...
- 淘宝API调用 申请 获取session key
在调用淘宝的API时,我们都会用到appkey,appsecret,appsession. 1.我们申请应用就会有appkey和appsecret了 2.正式环境下获取SessionKey 注意:we ...
- poj 2236
Wireless Network Time Limit: 10000MS Memory Limit: 65536K Total Submissions: 25817 Accepted: 107 ...
- oracle 数据库删除表或表数据恢复问题
oracle恢复误删除的数据:使用闪回,ORACLE 10G及以上版本! 1. flashback table table_name to timestamp systimestamp-1; (sys ...
- HTML入门第二天
一. URL url:统一资源定位符 组成: 协议://域名:端口号/文件?参数名1=值1&参数名2=值2 例子:http://www.163.com:80/index.html?userna ...
- tp框架 :操作数据库
操作数据库,进行增删改数据 一.对数据表添加数据(方法:add()) (1)上一篇已经讲过链接数据库了,继续进行对数据库的操作,还是用控制器文件中的HomeController.class文件 看下数 ...
- mongoDB & Nodejs 访问mongoDB (二)
非常详细的文档http://mongodb.github.io/node-mongodb-native/2.2/quick-start/quick-start/ 连接数据库 安装express 和 m ...
- ehcache memcache redis 区别
之前用过redis 和 memcache ,没有ehcache 的开发经验,最近也查阅不少文档和博客,写一些总结,也有不少内容总结与诸多博客中的博主总结: Ehcache EhCache 是一个纯J ...