Codeforces629 C. Famil Door and Brackets】的更多相关文章

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…
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 题目连接: 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…
题目链接: 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…
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…
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 round brackets since Famil Door loves string of brackets of length n more than any other strings!…
题目大概说给一个长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. 那么转移,我用我为人人…
题目链接: http://codeforces.com/contest/629/problem/C 题意: 长度为n的括号,已经知道的部分的长度为m,现在其前面和后面补充‘(',或')',使得其长度为n,且每个左括号都能找到右括号与它匹配. 题解: dp[i][j]表示长度为i,平衡度为j的合法括号序列的总数,这里平衡度定义是‘('比')'多多少个,或')'比’('多多少个. #include<iostream> #include<cstring> #include<cstd…
题意:给你一个由括号组成的字符串,长度为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…
题意:给你一个长度为n的括号匹配串(不一定恰好匹配),让你在这个串的前面加p串和后面加上q串,使得这个括号串平衡(平衡的含义是对于任意位置的括号前缀和大于等于0,且最后的前缀和为0). 思路:枚举这个字符串前面p字符串的长度,我们可以使得p字符串的前缀和大于等于字符串s的最小前缀和minx,那么p+s就符合前缀和大于等于0,然后q的方案数也能确定了.我们用dp[i][j]表示i个括号平衡度为j的方案数,那么可以先预处理出来dp的值.然后我们算出s字符串的最小前缀和minx,最后我们只要枚举p的长…