Codeforces Round #343 (Div. 2) C. Famil Door and Brackets

时间:2023-02-14 17:06:15

题目链接:

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 &num;343 &lpar;Div&period; 2&rpar; C&period; Famil Door and Brackets dp

    C. Famil Door and Brackets 题目连接: http://www.codeforces.com/contest/629/problem/C Description As Fami ...

  2. Codeforces Round &num;343 &lpar;Div&period; 2&rpar; E&period; 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 &num;343 &lpar;Div&period; 2&rpar; E&period; Famil Door and Roads

    题目链接: http://www.codeforces.com/contest/629/problem/E 题解: 树形dp. siz[x]为x这颗子树的节点个数(包括x自己) dep[x]表示x这个 ...

  4. Codeforces Round &num;343 &lpar;Div&period; 2&rpar; E&period; Famil Door and Roads &lpar;树形dp&comma;lca&rpar;

    Famil Door's City map looks like a tree (undirected connected acyclic graph) so other people call it ...

  5. Codeforces Round &num;343 &lpar;Div&period; 2&rpar;

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

  6. Codeforces Round &num;343 &lpar;Div&period; 2&rpar; B&period; Far Relative’s Problem 暴力

    B. Far Relative's Problem 题目连接: http://www.codeforces.com/contest/629/problem/B Description Famil Do ...

  7. Codeforces Round &num;343 &lpar;Div&period; 2&rpar; B

    B. Far Relative’s Problem time limit per test 2 seconds memory limit per test 256 megabytes input st ...

  8. Codeforces Round &num;343 &lpar;Div&period; 2&rpar; A&period; Far Relative’s Birthday Cake 水题

    A. Far Relative's Birthday Cake 题目连接: http://www.codeforces.com/contest/629/problem/A Description Do ...

  9. Codeforces Round &num;343 &lpar;Div&period; 2&rpar;-629A&period; Far Relative’s Birthday Cake 629B&period; Far Relative’s Problem

    A. Far Relative's Birthday Cake time limit per test 1 second memory limit per test 256 megabytes inp ...

随机推荐

  1. jquery&period;uploadify上传文件配置详解&lpar;asp&period;net mvc&rpar;

    页面源码: <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" c ...

  2. QQ空间HD&lpar;6&rpar;-实现自定义的选项卡切换效果

    DJTabbarButton.m #import "DJTabbarButton.h" @implementation DJTabbarButton - (instancetype ...

  3. sql数据库&lpar;资料库&rpar;的基本操作

    1 Character Set与Collation 任何资讯技术在处理资料的时候,如果只是单纯的数值和运算,那就不会有太复杂的问题:如果处理的资料是文字的话,就会面临世界上各种不同语言的问题.以资料库 ...

  4. C语言警告:warning C4018&colon; &ldquo&semi;&lt&semi;&rdquo&semi;&colon; 有符号&sol;无符号不匹配

    问题如下: 代码出问题之处:   原因分析: strlen返回一个无符号整型,也就是unsigned型,比较时应该两边的数据类型相同,故严格上来说,应该将m定义为unsigned型.       修改 ...

  5. Mysql忘记密码修改密码

    问题重现(以下讨论范围仅限Windows环境): C:\AppServ\MySQL> mysql -u root -p Enter password: ERROR 1045 (28000): A ...

  6. Unity编辑器扩展Texture显示选择框

    学习NGUI插件的时候,突然间有一个问题为什么它这些属性可以通过弹出窗口来选中呢? 而我自己写的组件只能使用手动拖放的方式=.=. Unity开发了组件Inspector视图扩展API,如果我们要写插 ...

  7. BZOJ 3626&colon; &lbrack;LNOI2014&rsqb;LCA&lpar; 树链剖分 &plus; 离线 &rpar;

    说多了都是泪啊...调了这么久.. 离线可以搞 , 树链剖分就OK了... -------------------------------------------------------------- ...

  8. Vue实现商城里面多个商品计算,全选,删除

    <!--包含 全选/不全选 批量删除 全部金额计算 数量加减--> 简陋的CSS代码 .main{ width: 100%;}.title{ width: 100%; height: 40 ...

  9. 20&period;1章JSON语法

    1,语法 JSON有三种类型的值 简单值:使用与JavaScript相同的语法,可以在JSON中表示字符串,数值,布尔值,null.但是JSON不支持JavaScript中特殊的值undefined. ...

  10. FATAL Fatal error during KafkaServerStable startup&period; Prepare to shutdown &lpar;kafka&period;server&period;KafkaServerStartable&rpar; java&period;io&period;FileNotFoundException&colon; &sol;tmp&sol;kafka-logs&sol;&period;lock &lpar;Permission denied&rpar;

    1.启动kafka的时候,报错如下所示: [-- ::,] INFO zookeeper state changed (SyncConnected) (org.I0Itec.zkclient.ZkCl ...