POJ 3991 括号匹配问题(贪心)】的更多相关文章

I’m out of stories. For years I’ve been writing stories, some rather silly, just to make simple problems look difficult and complex problems look easy. But, alas, not for this one. You’re given a non empty string made in its entirety from opening and…
题意:给你一些括号,问匹配规则成立的括号的个数. 思路:这题lrj的黑书上有,不过他求的是添加最少的括号数,是的这些括号的匹配全部成立. 我想了下,其实这两个问题是一样的,我们可以先求出括号要匹配的最少数量,那么设原来括号的数量为l , 添加了l' . 那么其实原来括号匹配成功的括号数就是((l + l') / 2 - l') * 2. #define N 105 char a[N] ; int dp[N][N] ; int f[N][N] ; int check(int i ,int j) {…
Brackets Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 6033   Accepted: 3220 Description We give the following inductive definition of a “regular brackets” sequence: the empty sequence is a regular brackets sequence, if s is a regular…
黑书原题 区间DP,递归输出 不看Discuss毁一生 (woc还真有空串的情况啊) //By SiriusRen #include <cstdio> #include <cstring> #include <algorithm> using namespace std; int n,f[111][111]; char s[111]; void print(int l,int r){ if(l==r){if(s[l]=='('||s[r]==')')printf(&qu…
编程题#4:扩号匹配问题 来源: POJ(Coursera声明:在POJ上完成的习题将不会计入Coursera的最后成绩.) 注意: 总时间限制: 1000ms 内存限制: 65536kB 描述 在某个字符串(长度不超过100)中有左括号.右括号和大小写字母:规定(与常见的算数式子一样)任何一个左括号都从内到外与在它右边且距离最近的右括号匹配.写一个程序,找到无法匹配的左括号和右括号,输出原来字符串,并在下一行标出不能匹配的括号.不能匹配的左括号用"$"标注,不能匹配的右括号用&quo…
题目链接:http://poj.org/problem?id=2955 题目大意:给你一串字符串,求最大的括号匹配数. 解题思路: 设dp[i][j]是[i,j]的最大括号匹配对数. 则得到状态转移方程: if(str[i]=='('&&str[j]==')'||(str[i]=='['&&str[j]==']')){ dp[i][j]=dp[i+1][j-1]+1; }dp[i][j]=min(dp[i][j],dp[i][k]+dp[k+1][j]) ,(i<=k…
题目链接:http://poj.org/problem?id=1141 题目大意:给你一串字符串,让你补全括号,要求补得括号最少,并输出补全后的结果. 解题思路: 开始想的是利用相邻子区间,即dp[i+1][j]之类的方法求,像是求回文串的区间DP一样.然后花了3个多小时,GG... 错误数据: (())(]][[)my:6 (()()()[][][][])ans:4 (())([][][][])括号匹配跟回文串不同,并不能通过dp[i+1][j]或者dp[i][j-1]推得dp[i][j],可…
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=6299 题目: 题意:t组数据,每组数据给你一个n表示给你n个括号串,这n个括号串之间进行组合,求能够匹配的长度. 思路:用一个结构体来记录每个字符串的左括号和右括号的数量,在输入时将同串中能够匹配的直接消掉,最后剩余的字符绝对是所有的右括号在左边,左括号在右边,假设当前字符串为())(()(,我们一次将其标记为1~7,那么1和2可以匹配,5可以和6匹配,最后剩余347,也就是)((.我们紧接着就对n…
题目链接:Brackets Sequence 题目描写叙述:给出一串由'(')'' [ ' ' ] '组成的串,让你输出加入最少括号之后使得括号匹配的串. 分析:是区间dp的经典模型括号匹配.解说:http://blog.csdn.net/y990041769/article/details/24194605 ,难点在于要把匹配后的括号输出来. 首先我们知道前面定义dp [ i ] [ j ] 为串中第 i 个到第 j 个括号的最大匹配数目 那么假如我们知道随意 i 到 j 从哪儿插入分点使得匹…
Description We give the following inductive definition of a “regular brackets” sequence: the empty sequence is a regular brackets sequence, if s is a regular brackets sequence, then (s) and [s] are regular brackets sequences, and if a and b are regul…