poj 1141】的更多相关文章

首先考虑下面的问题:Code[VS] 3657 我们用以下规则定义一个合法的括号序列: (1)空序列是合法的 (2)假如S是一个合法的序列,则 (S) 和[S]都是合法的 (3)假如A 和 B 都是合法的,那么AB和BA也是合法的 例如以下是合法的括号序列: (), [], (()), ([]), ()[], ()[()] 以下是不合法括号序列的: (, [, ], )(, ([]), ([() 现在给定一些由'(', ')', '[', ,']'构成的序列 ,请添加尽量少的括号,得到一个合法的…
题目链接:http://poj.org/problem?id=1141 题解:求已知子串最短的括号完备的全序列 代码: #include<iostream> #include<cstdio> #include<algorithm> #include<cstring> using namespace std; #define ll long long ; const int INF=0x3f3f3f3f; ][]; ][]; ]; int Find(int x…
题目:http://poj.org/problem?id=1141 转载:http://blog.csdn.net/lijiecsu/article/details/7589877 定义合法的括号序列如下: 1 空序列是一个合法的序列 2 如果S是合法的序列,则(S)和[S]也是合法的序列 3 如果A和B是合法的序列,则AB也是合法的序列 例如:下面的都是合法的括号序列 (),  [],  (()),  ([]),  ()[],  ()[()] 下面的都是非法的括号序列 (,  [,  ),  …
题目链接: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],可…
A bottom-up DP. To be honest, it is not easy to relate DP to this problem. Maybe, all "most"\"least" problems can be solved using DP.. Reference: http://blog.sina.com.cn/s/blog_8e6023de01014ptz.html There's an important details to AC:…
Brackets Sequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 29520   Accepted: 8406   Special Judge Description Let us define a regular brackets sequence in the following way: 1. Empty sequence is a regular sequence. 2. If S is a re…
又几天没写博客了,大二的生活实在好忙碌啊,开了五门专业课,每周都是实验啊实验啊实验啊....我说要本月刷够60题,但好像完不成了,也就每天1题的样子.如今写动规还是挺有条理的,包括这道需要打印轨迹,其实就是在POJ 2955的基础上进行下修改,记录下动规的方向,再用递归逆向输出即可! 是个区间DP,如果 括号i和括号k匹配了,则 dp[i][j]=max(dp[i][j],dp[i][k]+1+dp[k+1][j])这个转移方程挺重要的,我一开始就是这个方程没写好..弄得思路混乱了 还有就是一开…
简单的dp 忘了\n,调了半天(目测不是第一次了) 直接贴代码: #include<cstdio> #include<cstring> using namespace std; char s[120]; int dp[120][120]={0}; int min(int x,int y){ return (x>y)?y:x; } void solve(int x,int y){ if(dp[x][y]==0){ for(int i=x;i<=y;i++) printf(…
Brackets Sequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 30383   Accepted: 8712   Special Judge Description Let us define a regular brackets sequence in the following way: 1. Empty sequence is a regular sequence. 2. If S is a re…
题目链接 很早 很早之前就看过的一题,今天终于A了.状态转移,还算好想,输出路径有些麻烦,搞了一个标记数组的,感觉不大对,一直wa,看到别人有写直接输出的..二了,直接输出就过了.. #include <cstdio> #include <cstring> #include <iostream> using namespace std; ][]; ]; ]; ]; int dfs(int L,int R) { int i,minz; if(dp[L][R]) retur…