BNUOJ 1260 Brackets Sequence】的更多相关文章

Brackets Sequence Time Limit: 1000ms Memory Limit: 65536KB This problem will be judged on PKU. Original ID: 114164-bit integer IO format: %lld      Java class name: Main Special Judge   Let us define a regular brackets sequence in the following way:…
Brackets Sequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 27793   Accepted: 7885   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…
Brackets Sequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 29502   Accepted: 8402   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…
Description Let us define a regular brackets sequence in the following way: 1. Empty sequence is a regular sequence. 2. If S is a regular sequence, then (S) and [S] are both regular sequences. 3. If A and B are regular sequences, then AB is a regular…
题目传送门 /* 记忆化搜索(DP+DFS):dp[i][j] 表示第i到第j个字符,最少要加多少个括号 dp[x][x] = 1 一定要加一个括号:dp[x][y] = 0, x > y; 当s[x] 与 s[y] 匹配,则搜索 (x+1, y-1); 否则在x~y-1枚举找到相匹配的括号,更新最小值 */ #include <cstdio> #include <algorithm> #include <cmath> #include <iostream&…
Let us define a regular brackets sequence in the following way: 1. Empty sequence is a regular sequence. 2. If S is a regular sequence, then (S) and [S] are both regular sequences. 3. If A and B are regular sequences, then AB is a regular sequence. F…
Brackets Sequence Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 35049   Accepted: 10139   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 r…
[poj P1141] Brackets Sequence Time Limit: 1000MS   Memory Limit: 65536K   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 regular sequence, then (S) and […
Description ]. Output For each test case, print how many places there are, into which you insert a '(' or ')', can change the sequence to a regular brackets sequence. What's more, you can assume there has at least one such place. Sample Input 4 ) ())…
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…
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…
Description Let us define a regular brackets sequence in the following way: 1. Empty sequence is a regular sequence. 2. If S is a regular sequence, then (S) and [S] are both regular sequences. 3. If A and B are regular sequences, then AB is a regular…
Let us define a regular brackets sequence in the following way: Empty sequence is a regular sequence. If S is a regular sequence, then (S) and [S] are both regular sequences. If A and B are regular sequences, then AB is a regular sequence. For exampl…
题目链接:https://icpcarchive.ecs.baylor.edu/index.php?option=com_onlinejudge&Itemid=8&category=98&page=show_problem&problem=452 用dp[i][j] 记录一段序列,starts from index i, ends with index j,需要添加的char的个数.对于一段序列i~j,如果i, j 配对的话,那么dp[i][j]=dp[i+1][j-1].…
Wavio Sequence Time Limit: 3000ms Memory Limit: 131072KB This problem will be judged on UVA. Original ID: 1053464-bit integer IO format: %lld      Java class name: Main   Wavio is a sequence of integers. It has some interesting properties. Wavio is o…
题目链接: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…
题目链接 很早 很早之前就看过的一题,今天终于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…
题意:用最少的括号将给定的字符串匹配,输出最优解.可能有空行. 思路:dp. dp[i][j]表示将区间i,j之间的字符串匹配需要的最少括号数,那么 如果区间左边是(或[,表示可以和右边的字符串匹配,枚举中间断点k,如果str[i]==str[k]则dp[i][j]=min(dp[i][j],dp[i+1][k-1]+dp[k+1][j])表示不需要加入新的括号,也可以插入新的括号则dp[i][j]=min(dp[i][j],dp[i+1][k]+dp[k+1][j]+1). 如果区间最左边字符…
http://acm.hust.edu.cn/vjudge/contest/view.action?cid=105116#problem/E 题意:添加最少的括号,让每个括号都能匹配并输出 分析:dp[i][j]表示第i个到第j个需要添加的最少的括号,pos[i][j] = k;表示i到j间第k个需要加括号: 如果str[i]和str[j]匹配,那么dp[i][j] = max(dp[i + 1][j - 1], dp[i][j]); 如果str[i]和str[j]不匹配,那么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:…
本文出自:http://blog.csdn.net/svitter 原题:http://poj.org/problem?id=1141 题意:输出添加括号最少,并且使其匹配的串. 题解: dp [ i ] [ j ] 表示添加括号的个数, pos[ i][ j ] 表示 i , j 中哪个位置分开,使得两部分分别匹配. pos [ i ][ j ] 为-1的时候,说明i, j 括号匹配. 初始值置dp [ i ] [ i ]  = 1; 如果只有一个括号,那么匹配结果必然是差1. 首先判断括号是…
题目链接 题意 : 给你一串由括号组成的串,让你添加最少的括号使该串匹配. 思路 : 黑书上的DP.dp[i][j] = min{dp[i+1][j-1] (sh[i] == sh[j]),dp[i][k]+dp[k+1][j](i<=k<j)}.输出的时候递归,其实我觉得输出比dp部分难多了..... #include <stdio.h> #include <string.h> #include <iostream> using namespace std…
正规括号序列定义为: 空序列是正规括号序列 如果S是正规括号序列,那么[S]和(S)也是正规括号序列 如果A和B都是正规括号序列,则AB也是正规括号序列 输入一个括号序列,添加尽量少的括号使之成为正规括号序列,并输出最优方案,多解的话输出任意一个即可. 设d(i, j)表示字符串s[i]~s[j]至少添加的括号的数量,则转移如下: S形如[S']或(S'),则转移到d(i+1, j-1) 如果S至少有两个字符,将其分为AB,转移到min{d(i, j), d(A) + d(B)} 不管是否满足第…
题意: 给你一个括号序列(有中小括号),求出以给定序列为子序列的最小合法括号序列. 分析: 非常经典,以前做过相似一道题,用区间dp,但怎么把这个序列求出来没想出来. dp[i][j]表示区间i-j是序列合法要增加括号的最小数量,并pos[i][j]表示i-j在哪个位置断开最小,最后通过递归位置打印出答案. 此题序列可能是空串. #include <map> #include <set> #include <list> #include <cmath> #i…
经典DP问题,注意输入不要使用while(xxx != EOF),否则WA,测试数据只有一组.同样的测试数据可能有多种答案.但最小长度唯一.一定不能用while,切记. #include <iostream> using namespace std; #include <string> #define MAXNUM 200 #define MAXVAL 32767 string match(char []); int main() { string regstr; char str…
题目链接: http://acm.xmu.edu.cn/JudgeOnline/problem.php?id=1033 http://poj.org/problem?id=1141 ZOJ目前挂了. 题目大意: 给一个括号序列,要求输出,最少增加括号数情况下,任意一个合法括号序列即可. 匹配是指()和[]完全合法,可以嵌套. 题目思路: [动态规划] 区间DP,枚举左右区间端点,两种匹配方法:中间拆开匹配或者直接头尾匹配. 转移得到最优值,同时记录得到最优值的方法,最后逆推得到不用增加的括号位置…
题目:http://poj.org/problem?id=1141 转载:http://blog.csdn.net/lijiecsu/article/details/7589877 定义合法的括号序列如下: 1 空序列是一个合法的序列 2 如果S是合法的序列,则(S)和[S]也是合法的序列 3 如果A和B是合法的序列,则AB也是合法的序列 例如:下面的都是合法的括号序列 (),  [],  (()),  ([]),  ()[],  ()[()] 下面的都是非法的括号序列 (,  [,  ),  …
题意:给定一个括号序列,将它变成匹配的括号序列,可能多种答案任意输出一组即可.注意:输入可能是空串. 思路:D[i][j]表示区间[i, j]至少需要匹配的括号数,转移方程D[i][j] = min(D[i][k] + D[k+1][j], D[i][j]).     输入时,可能是空串应该用gets.fgets.getline,应注意换行符的吸收.每组数据前有一个换行符,输出的两组数据之间有换行. AC代码: #include<cstdio> #include<vector> #…
题目描写叙述: 定义合法的括号序列例如以下: 1 空序列是一个合法的序列 2 假设S是合法的序列.则(S)和[S]也是合法的序列 3 假设A和B是合法的序列.则AB也是合法的序列 比如:以下的都是合法的括号序列 (),  [],  (()),  ([]),  ()[],  ()[()] 以下的都是非法的括号序列 (,  [,  ),  )(,  ([)],  ([(] 给定一个由'(',  ')',  '[', 和 ']' 组成的序列,找出以该序列为子序列的最短合法序列. 思路:真是经典的题目.…
URAL 1183 思路:区间dp,打印路径,详见http://www.cnblogs.com/widsom/p/8321670.html 代码: #include<iostream> #include<cstdio> #include<cstring> #include<string> #include<cmath> #include<algorithm> using namespace std; #define ll long l…