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

代码:
#include<bits/stdc++.h>
using namespace std;
#define Fopen freopen("_in.txt","r",stdin); freopen("_out.txt","w",stdout);
#define LL long long
#define ULL unsigned LL
#define fi first
#define se second
#define pb push_back
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define lch(x) tr[x].son[0]
#define rch(x) tr[x].son[1]
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
typedef pair<int,int> pll;
const int inf = 0x3f3f3f3f;
const int _inf = 0xc0c0c0c0;
const LL INF = 0x3f3f3f3f3f3f3f3f;
const LL _INF = 0xc0c0c0c0c0c0c0c0;
const LL mod = (int)1e9+;
const int N = 2e5 + ;
int F[N], Finv[N], inv[N];/// F是阶层 Finv是逆元的阶层
void init(){
inv[] = ;
for(int i = ; i < N; i++)
inv[i] = (mod - mod/i) * 1ll * inv[mod % i] % mod;
F[] = Finv[] = ;
for(int i = ; i < N; i++){
F[i] = F[i-] * 1ll * i % mod;
Finv[i] = Finv[i-] * 1ll * inv[i] % mod;
}
}
int comb(int n, int m){ /// C(n,m)
if(m < || m > n) return ;
return F[n] * 1ll * Finv[n-m] % mod * Finv[m] % mod;
}
char s[N];
int l[N], r[N];
int main(){
scanf("%s", s+);
int n = strlen(s+);
for(int i = ; i <= n; ++i){
if(s[i] == '(') l[i]++;
l[i] += l[i-];
}
for(int i = n; i >= ; --i){
if(s[i] == ')') r[i]++;
r[i] += r[i+];
}
LL ans = ;
init();
for(int i = ; i <= n; ++i){
if(s[i] == '('){
ans = (ans + comb(l[i]-+r[i], l[i]))%mod;
}
}
cout << ans << endl;
return ;
}
CodeForces 785 D Anton and School - 2 范德蒙恒等式的更多相关文章
- Codeforces 785 D.Anton and School - 2(组合数处理)
Codeforces 785 D.Anton and School - 2 题目大意:从一串由"(",")"组成的字符串中,找出有多少个子序列满足:序列长度为偶 ...
- Codeforces 785 E. Anton and Permutation(分块,树状数组)
Codeforces 785 E. Anton and Permutation 题目大意:给出n,q.n代表有一个元素从1到n的数组(对应索引1~n),q表示有q个查询.每次查询给出两个数l,r,要求 ...
- 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 ...
- CF #404 (Div. 2) D. Anton and School - 2 (数论+范德蒙恒等式)
题意:给你一个由'('和')'组成的字符串,问你有多少个子串,前半部分是由'('组成后半部分由')'组成 思路:枚举这个字符串中的所有'('左括号,它左边的所有'('左括号的个数为num1,它的右边的 ...
- Codeforces 785D - Anton and School - 2 - [范德蒙德恒等式][快速幂+逆元]
题目链接:https://codeforces.com/problemset/problem/785/D 题解: 首先很好想的,如果我们预处理出每个 "(" 的左边还有 $x$ 个 ...
- Codeforces 785 D. Anton and School - 2
题目链接:http://codeforces.com/contest/785/problem/D 我们可以枚举分界点,易知分界点左边和右边分别有多少个左括号和右括号,为了不计算重复我们强制要求选择分界 ...
- Codeforces 785 - A/B/C/D/E - (Undone)
链接:https://codeforces.com/contest/785 A - Anton and Polyhedrons #include<bits/stdc++.h> using ...
- bzoj 4830: [Hnoi2017]抛硬币 [范德蒙德卷积 扩展lucas]
4830: [Hnoi2017]抛硬币 题意:A投a次硬币,B投b次硬币,a比b正面朝上次数多的方案数,模\(10^k\). \(b \le a \le b+10000 \le 10^{15}, k ...
- 浅谈范德蒙德(Vandermonde)方阵的逆矩阵的求法以及快速傅里叶变换(FFT)中IDFT的原理
浅谈范德蒙德(Vandermonde)方阵的逆矩阵与拉格朗日(Lagrange)插值的关系以及快速傅里叶变换(FFT)中IDFT的原理 标签: 行列式 矩阵 线性代数 FFT 拉格朗日插值 只要稍微看 ...
随机推荐
- 【WPF】 InkCanvas 书写毛笔效果
首先贴出本文参考学习的文章吧. https://www.cnblogs.com/LCHL/p/9055642.html#4206298 感谢这位懒羊羊的代码和讲解(下简称羊博主),我在此基础上稍微加了 ...
- druid0.15.0安装方式
Druid0.15.0安装文档 1 集群规划 Master包含Coordinator和Overlord,4核16G*2: data包含Historical和MiddleManager,16核64G*3 ...
- Python中的inf与nan
Python中可以用如下方式表示正负无穷 >>> float('inf') # 正无穷,inf不区分大小写,float('InF')一样可以. inf >>> fl ...
- Python中input()的使用方法
input()以字符串的方式获取用户输入: >>> x = input() 4.5 >>> type(x) <class 'str'> >> ...
- caddy & grpc(3) 为 caddy 添加一个 反向代理插件
caddy-grpc 为 caddy 添加一个 反向代理插件 项目地址:https://github.com/yhyddr/caddy-grpc 前言 上一次我们学习了如何在 Caddy 中扩展自己想 ...
- 在MAC终端下打开Finder:
在Terminal中打开Finder: open . 在Finder中打开Terminal: 系统偏好设置 -> 键盘 -> 快捷键 -> 服务,勾选「新建位于文件夹位置的终端窗口」
- Markdown 基本语法(后面继续补充)
1.1 Markdown 基础语法 有序内容和无序内容 有序内容:输入1.然后按tab键 无序内容:输入' * ' 或 ' - ' 然后后按tab键 字体的样式 *** 内容 *** 加粗加斜(中间没 ...
- Dubbo的基本介绍及使用
一,前言 在面对新技术新事物的时候,我们首先应该了解这是一个什么东东,了解为什么使用这门技术,如果我们不使用又会有什么影响.比如,本篇博客介绍Dubbo的基本使用,此时我们应该先要明白我为什么要使 ...
- zabbix自发现item监控
在zabbix监控中,我们可以通过自带item的可以和自定义key进行监控,但是当所需要的监控项不确定,比如key会根据时间进行变化时,这时候我们就不能把item的key定义死,要通过自发现这个高级功 ...
- R 实用命令 2
1. how to temporarily unload the packages in R > library(Daim) 载入程辑包:‘Daim’ The following objects ...