题目链接:

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的更多相关文章

  1. 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 ...

  2. 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 ...

  3. 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这个 ...

  4. 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 ...

  5. Codeforces Round #343 (Div. 2)

    居然补完了 组合 A - Far Relative’s Birthday Cake import java.util.*; import java.io.*; public class Main { ...

  6. 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 ...

  7. 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 ...

  8. 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 ...

  9. 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 ...

随机推荐

  1. JavaScript之点击文字放大

    function box(){ document.getElementById("click").style.WebkitTransform="scale(1.2)&qu ...

  2. sql server存储过程相关

    1,创建存储过程 create proc proc_test with encryption[这里是对存储过程加密],如果存储过程不常用可以加with recompile[这样存储过程就不会放到缓存里 ...

  3. 浅谈sqlserver数据库优化(一)----开光篇

    今天暂时无事,风和日丽,万里无云.游山的.玩水的.遛麻雀的都闲的不亦乐乎,也忙的不亦乐乎.在这美好的季节,依旧躲在被窝或是电脑旁绞尽脑汁敲键盘的人们,也别有一番滋味.废话少说,言归正传. 赶上了一个最 ...

  4. view, surfaceView, invalidate, postInvalidate, 刷新屏幕

    http://blog.csdn.net/linghu_java/article/details/9985489 1.view view在api中的结构 Java.lang.Object Androi ...

  5. [转]oracle 实现插入自增列

    本文转自:http://blog.csdn.net/love_zt_love/article/details/7911104 刚使用oracle,它和sql server 好多地方还是有所不同的,简单 ...

  6. 第十篇、让UIScrollView的滚动条常显

    UIScrollView滚动条一直显示 1.我们知道滚动条是一个UIImageView, 滚动条隐藏是因为设置了alpha属性为0, 所有我们写一个UIImageView的分类 #define noD ...

  7. 整理一下前段时间在写iOS app时所涉及的东西

    在刚学习和做完一个android app后,看了两周的Objective-C就开始做这个项目,所以整个app代码有很多现学现用的东西,今天来总结一下. 这个名为VID的app是用于公司产品的研发与de ...

  8. [Silverlight] Visual Studio2010不能安装Silverlight4_Tools,提示语言不一致

    今天在装Silverlight4_Tools时出现“必须先安装与 Silverlight Tools 4 语言版本相一致的 Visual Studio 2010.Visual Web Develope ...

  9. GDAL中RasterIO函数(把文件读取为一个一维数组)和ReadBlock函数(读取栅格数据块)

    CPLErr GDALRasterBand::RasterIO ( GDALRWFlag eRWFlag, int nXOff, int nYOff, int nXSize, int nYSize, ...

  10. 模拟抛硬币(C语言实现)

    实现代码: #include<stdio.h> #include<stdlib.h> int heads() { ; } int main(int argc, char *ar ...