Codeforces Round #343 (Div. 2) C. Famil Door and Brackets
题目链接:
http://codeforces.com/contest/629/problem/C
题意:
长度为n的括号,已经知道的部分的长度为m,现在其前面和后面补充‘(',或')',使得其长度为n,且每个左括号都能找到右括号与它匹配。
题解:
dp[i][j]表示长度为i,平衡度为j的合法括号序列的总数,这里平衡度定义是‘('比')'多多少个,或')'比’('多多少个。
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace std; const int maxn = ;
const int maxm = 1e5 + ;
const int mod = 1e9 + ;
const int INF = 0x3f3f3f3f;
typedef __int64 LL; LL dp[maxn][maxn];
void pre() {
memset(dp, , sizeof(dp));
dp[][] = ;
for (int i = ; i < maxn; i++) {
dp[i][] = dp[i - ][];
for (int j = ; j <= i; j++) {
dp[i][j] = (dp[i - ][j - ] + dp[i - ][j + ]) % mod;
}
}
} int n, m;
char str[maxm]; int main() {
pre();
scanf("%d%d", &n, &m);
scanf("%s", str);
int l = , r = , mi = INF;
for (int i = ; i < m; i++) {
if (str[i] == '(') l++;
else r++;
mi = min(mi, l - r);
}
LL ans = ;
for (int i = ; i <= n - m; i++) {
for (int j = max(, -mi); j <= i; j++) {
int t = j + l - r;
if (t > n - m - i) continue;
ans = (ans + dp[i][j] * dp[n - m - i][t] % mod) % mod;
}
}
printf("%I64d\n", ans);
return ;
}
Codeforces Round #343 (Div. 2) C. Famil Door and Brackets的更多相关文章
- Codeforces Round #343 (Div. 2) C. Famil Door and Brackets dp
C. Famil Door and Brackets 题目连接: http://www.codeforces.com/contest/629/problem/C Description As Fami ...
- Codeforces Round #343 (Div. 2) E. Famil Door and Roads lca 树形dp
E. Famil Door and Roads 题目连接: http://www.codeforces.com/contest/629/problem/E Description Famil Door ...
- Codeforces Round #343 (Div. 2) E. Famil Door and Roads
题目链接: http://www.codeforces.com/contest/629/problem/E 题解: 树形dp. siz[x]为x这颗子树的节点个数(包括x自己) dep[x]表示x这个 ...
- Codeforces Round #343 (Div. 2) E. Famil Door and Roads (树形dp,lca)
Famil Door's City map looks like a tree (undirected connected acyclic graph) so other people call it ...
- Codeforces Round #343 (Div. 2)
居然补完了 组合 A - Far Relative’s Birthday Cake import java.util.*; import java.io.*; public class Main { ...
- Codeforces Round #343 (Div. 2) B. Far Relative’s Problem 暴力
B. Far Relative's Problem 题目连接: http://www.codeforces.com/contest/629/problem/B Description Famil Do ...
- Codeforces Round #343 (Div. 2) B
B. Far Relative’s Problem time limit per test 2 seconds memory limit per test 256 megabytes input st ...
- Codeforces Round #343 (Div. 2) A. Far Relative’s Birthday Cake 水题
A. Far Relative's Birthday Cake 题目连接: http://www.codeforces.com/contest/629/problem/A Description Do ...
- Codeforces Round #343 (Div. 2)-629A. Far Relative’s Birthday Cake 629B. Far Relative’s Problem
A. Far Relative's Birthday Cake time limit per test 1 second memory limit per test 256 megabytes inp ...
随机推荐
- GitHub之上传文件
github是一个基于git的代码托管平台,付费用户可以建私人仓库,我们一般的免费用户只能使用公共仓库,也就是代码要公开.对于一般人来说公共仓库就已经足够了,而且我们也没多少代码来管理,O(∩_∩)O ...
- linux中ftp用户登录密码忘记了怎么修改
先来熟悉一下 vsftp 命令: 启动vsftp用命令: 1.service vsftpd start 重启vsftp用: www.111cn.net1.service vsftpd restart ...
- Cisco模拟器使用和静态路由配置
一. 模拟器使用 网络拓扑图 1. 模拟器搭建环境及网络结构 2. 使用ios系统加载并配置 3. 加载3745ios后计算pc值以减小cpu的消耗 4. 然后使用CTRL+]+i得到最大的一个值(如 ...
- ReactiveCocoa比较区分replay, replayLast和replayLazily
一直搞不清楚replayLazily和replay的区别可以直接跳到最后看. 原文:http://spin.atomicobject.com/2014/06/29/replay-replaylast- ...
- WPF串口通信数据采集
使用WPF做的串口数据采集并动态显示在表格中的小程序,程序运行之后,自动打开串口,从COM1接收数据,并把接收到的数据进行处理显示在DataGrid中. 串口通信程序是从另外一个串口助手中扒的,去掉了 ...
- UI3_UIViewController生命周期
// // SecondViewController.h // UI3_UIViewController生命周期 // // Created by zhangxueming on 15/7/2. // ...
- eclipse不能更改设置tomcat 中的ServerLocation问题
当自己用eclipse写好了web项目后,也同时配置了服务器(tomcat6), 上面部署完毕后,直接访问http://localhost:8080 发现是 无法访问的,这是因为,Servers这里的 ...
- linux exec函数族
1.简介 在Linux中,并不存在exec()函数,exec指的是一组函数,一共有6个,分别是: #include <unistd.h> extern char **environ; ...
- Windows Phone 8.1开发:如何从ListView中,获取ScrollViewer对象
在使用ListView作为信心呈现载体开发应用程序时,我们经常需要通过监视滚动条(ScrollViewer)的位置状态来完成一些交互逻辑.最直接的体现就是 延时加载,(上滑加载更多,下拉获取更新数据) ...
- eclipse juno版本中没用 ant
下载了谷歌提供的Android集成开发工具ADT,里面封装了Eclipse,但是很奇怪的是竟然没有Ant插件在里面 标准的Eclipse一般都是内置集成了Ant的. 然后到eclipse的plugin ...