CodeForces 629C Famil Door and Brackets】的更多相关文章

题目链接: codeforces 629C Famil Door and Brackets 题目描述: 给出完整的括号序列长度n,现在给出一个序列s长度为m.枚举串p,q,使得p+s+q是合法的括号串,长度为n,问p,q的取值数目. 解题思路: 枚举p的长度,可以直接得到q的长度.因为要满足在任意位置'(' 数目大于 ’)‘ 的数目,所以统计一下s串中 ’(‘ - ')' 的最小数目minx.dp[i][j] 代表 到位置 i 时,满足 '(' - ')' == j 的情况数目.然后枚举p的 j…
题目大概说给一个长m的括号序列s,要在其前面和后面添加括号使其变为合法的长度n的括号序列,p+s+q,问有几种方式.(合法的括号序列当且仅当左括号总数等于右括号总数且任何一个前缀左括号数大于等于右括号数) 我这么想的:n-m<=2000,因而可以dp计算p和q的方案数,同时在各个地方加入s进行转移. dp[0/1][i][j]表示s没有/有加入时,p和q前i个括号已经确定且还有j的左括号还没匹配的方案数 注意到任何前缀的左括号都是大于等于右括号的,因此j这一维不会小于0. 那么转移,我用我为人人…
题意:给你一个由括号组成的字符串,长度为m,现在希望获得一个长度为n(全由括号组成)的字符串,0<=n-m<=2000 这个长度为n的字符串要求有两个性质:1:就是任意前缀,左括号数量大于右括号数量 2:字符串中左括号的数量等于右括号 现在让你可以在长度为m的原串前加一个括号串p,在原串后加一个括号串q 最后p+m+q=n 问有多少种组合p,q能得到目标串 分析:(这题我不会,看了题解才会) 定义dp[i][j],为前缀长为i,且左括号数量-右括号数量=j的串有多少个 所以dp[0][0]=1…
DP. 具体做法:dp[i][j]表示长度为 i 的括号串,前缀和(左括号表示1,右括号表示-1)为 j 的有几种. 状态转移很容易得到:dp[i][j]=dp[i - 1][j + 1]+dp[i - 1][j - 1],表示 i 这位分别放上右括号和左括号. 然后就是要处理题目的问题了: 我们可以枚举P串的长度和P串的前缀和,来看这种情况下是否符合题目要求,如果符合答案增加. 那么如何判断P串长度为left,前缀和为p的情况下,有几种符合题目要求呢? 先对已经存在的那个S串做一次括号匹配,做…
C. Famil Door and Brackets 题目连接: http://www.codeforces.com/contest/629/problem/C Description As Famil Door's birthday is coming, some of his friends (like Gabi) decided to buy a present for him. His friends are going to buy a string consisted of roun…
Famil Door and Brackets Time Limit: 20 Sec  Memory Limit: 512 MB Description Input Output Sample Input 4 1 ( Sample Output 4 HINT Solution 显然,我们考虑运用DP.先求出 f[i][j] 表示 长度为 i 的括号序列,“)” 比 “(” 多 j 个的方案(时刻保证 j >= 0). 然后我们考虑怎样获得答案.先预处理出L,R表示将读入的括号序列消去若干对之后剩…
C. Famil Door and Brackets time limit per test 2 seconds memory limit per test 256 megabytes input standard input output standard output As Famil Door's birthday is coming, some of his friends (like Gabi) decided to buy a present for him. His friends…
time limit per test2 seconds memory limit per test256 megabytes inputstandard input outputstandard output As Famil Door's birthday is coming, some of his friends (like Gabi) decided to buy a present for him. His friends are going to buy a string cons…
题目链接: http://codeforces.com/contest/629/problem/C 题意: 长度为n的括号,已经知道的部分的长度为m,现在其前面和后面补充‘(',或')',使得其长度为n,且每个左括号都能找到右括号与它匹配. 题解: dp[i][j]表示长度为i,平衡度为j的合法括号序列的总数,这里平衡度定义是‘('比')'多多少个,或')'比’('多多少个. #include<iostream> #include<cstring> #include<cstd…
time limit per test1 second memory limit per test256 megabytes inputstandard input outputstandard output Vanya is doing his maths homework. He has an expression of form , where x1, x2, -, xn are digits from 1 to 9, and sign represents either a plus '…