题目链接:

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. 使用Bootstrap-Table 遇到的问题

    最近用bootstrap-Table插件,遇到的问题记录下: 1.如何按条件查询时,pageNumber重置为1? $('#btnSub').bind('click', function () { $ ...

  2. shell运行报 too many arguments错误

    有时候shell在运行的时候可能会报 too many arguments错误,出现这种错误的一般情况是出现了多值问题,也就是一个变量可能有多个值了. 例:#!/bin/sh echo "I ...

  3. JS闭包理解_摘

    原文地址1:http://www.cnblogs.com/mzwr1982/archive/2012/05/20/2509295.html 闭包是一个比较抽象的概念,尤其是对js新手来说.书上的解释实 ...

  4. Zend studio 12.5.1安装aptana

    aptana是zend studio的一个插件.解决zend对于前台html支持,加亮的问题. 安装方法其实很简单 ,直接给出aptana的地址了. http://download.aptana.co ...

  5. 使用eBay API基本步骤介绍

    要开始使用eBay API,需要如下基本步骤: 1.    注册开发帐号: https://developer.ebay.com/join/Default.aspx 2.    选择API类型: eB ...

  6. 20141201--JS Window

    一.window.screen 包含有关用户屏幕的信息. window.screen 对象在编写时可以不使用 window 这个前缀. 一些属性: screen.availWidth - 可用的屏幕宽 ...

  7. ios固定高度禁止惯性滚动

    最近测试pad改H5的项目时,固定高度的div,超出部分滚动,但在ios下滑动特别卡顿,安卓上没问题.搜索找到解决办法 固定高度的div设置超出页面滚动,ios会出现卡顿,非常不爽.通过下面css就可 ...

  8. idea基本

    IntelliJ IDEA特色功能 IDEA所提倡的是智能编码,是减少程序员的工作,IDEA的特色功能有以下25点:智能的选取在很多时候我们要选取某个方法,或某个循环或想一步一步从一个变量到整个类慢慢 ...

  9. CXF调用wsdl2java生成客户端异常

    用cxf生成java客户端代码的时候出现异常: undefined element declaration 's:schema'   解决办法:1.删除   2.替换   参考资料:   http:/ ...

  10. Android四大组件之一:Service(服务)

    Service跟Activity也是出于统一级别的组件,且与Activity的最大区别之一主要是没有人机界面,主要是运行在程序的后台(我是这么理解的),帮助文档上说的是运行于进程的主线程中,但是服务并 ...