题目链接:
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 ...
随机推荐
-
jquery.uploadify上传文件配置详解(asp.net mvc)
页面源码: <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" c ...
-
QQ空间HD(6)-实现自定义的选项卡切换效果
DJTabbarButton.m #import "DJTabbarButton.h" @implementation DJTabbarButton - (instancetype ...
-
sql数据库(资料库)的基本操作
1 Character Set与Collation 任何资讯技术在处理资料的时候,如果只是单纯的数值和运算,那就不会有太复杂的问题:如果处理的资料是文字的话,就会面临世界上各种不同语言的问题.以资料库 ...
-
C语言警告:warning C4018: &ldquo;<;&rdquo;: 有符号/无符号不匹配
问题如下: 代码出问题之处: 原因分析: strlen返回一个无符号整型,也就是unsigned型,比较时应该两边的数据类型相同,故严格上来说,应该将m定义为unsigned型. 修改 ...
-
Mysql忘记密码修改密码
问题重现(以下讨论范围仅限Windows环境): C:\AppServ\MySQL> mysql -u root -p Enter password: ERROR 1045 (28000): A ...
-
Unity编辑器扩展Texture显示选择框
学习NGUI插件的时候,突然间有一个问题为什么它这些属性可以通过弹出窗口来选中呢? 而我自己写的组件只能使用手动拖放的方式=.=. Unity开发了组件Inspector视图扩展API,如果我们要写插 ...
-
BZOJ 3626: [LNOI2014]LCA( 树链剖分 + 离线 )
说多了都是泪啊...调了这么久.. 离线可以搞 , 树链剖分就OK了... -------------------------------------------------------------- ...
-
Vue实现商城里面多个商品计算,全选,删除
<!--包含 全选/不全选 批量删除 全部金额计算 数量加减--> 简陋的CSS代码 .main{ width: 100%;}.title{ width: 100%; height: 40 ...
-
20.1章JSON语法
1,语法 JSON有三种类型的值 简单值:使用与JavaScript相同的语法,可以在JSON中表示字符串,数值,布尔值,null.但是JSON不支持JavaScript中特殊的值undefined. ...
-
FATAL Fatal error during KafkaServerStable startup. Prepare to shutdown (kafka.server.KafkaServerStartable) java.io.FileNotFoundException: /tmp/kafka-logs/.lock (Permission denied)
1.启动kafka的时候,报错如下所示: [-- ::,] INFO zookeeper state changed (SyncConnected) (org.I0Itec.zkclient.ZkCl ...