POJ 2955 Brackets (区间DP,常规)】的更多相关文章

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 regular brackets…
Brackets My Tags (Edit) Source : Stanford ACM Programming Contest 2004 Time limit : 1 sec Memory limit : 32 M Submitted : 188, Accepted : 113 5.1 Description We give the following inductive definition of a "regular brackets" sequence: • the empt…
传送门 https://www.cnblogs.com/violet-acmer/p/9852294.html 题意: 给你一个只由 '(' , ')' , '[' , ']' 组成的字符串s[ ],求最大匹配? 题解: 定义dp[ i ][ j ] : 从第i个字符到第j个字符的最大匹配. 步骤: (1) : 如果s[ i ] 与 s[ j ]匹配,那么dp[ i ][ j ] =  2+dp[ i+1 ][ j-1 ];反之,dp[ i ][ j ] = 0; (2) : 接下来,从 i 到…
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…
dp[i][j]代表i->j区间内最多的合法括号数 if(s[i]=='('&&s[j]==')'||s[i]=='['&&s[j]==']') dp[i][j]=dp[i+1][j-1]+2; dp[i][j]=max{dp[i][k]+dp[k+1][j]}; 注意要对于区间的最值合并 ac代码: #include<cstdio> #include<cstring> #include<algorithm> using names…
题目链接 #include <iostream> #include <cstdio> #include <cstring> #include <vector> #include <cmath> #include <algorithm> using namespace std; ][]; ]; int judge(int x,int y) { if(str[x] == '['&&str[y] == ']') ; else…
http://blog.csdn.net/libin56842/article/details/9673239 http://www.cnblogs.com/ACMan/archive/2012/08/09/2630497.html http://blog.csdn.net/chaiyuan414/article/details/5448699 #include <iostream> #include <string> #include <cstring> #inclu…
POJ 2995 Brackets 区间DP 题意 大意:给你一个字符串,询问这个字符串满足要求的有多少,()和[]都是一个匹配.需要注意的是这里的匹配规则. 解题思路 区间DP,开始自己没想到是区间DP,以为就是用栈进行模拟呢,可是发现就是不大对,后来想到是不是使用DP,但是开始的时候自己没有推出递推关系,后来实在想不出来看的题解,才知道是区间DP,仔细一想确实是啊. 下面就是状态转移方程: \[ \begin{cases}dp[i][j] &=& dp[i+1][j-1]+if(str…
题目链接:https://cn.vjudge.net/contest/276243#problem/A 题目大意:给你一个字符串,让你求出字符串的最长匹配子串. 具体思路:三个for循环暴力,对于一个区间i,j,我们先计算出这个区间内合法的有多少个,也就是 ][j-]+; 然后就开始求这个区间内的最大值就可以了. dp[k][j]=max(dp[k][j],dp[k][pos]+dp[pos+][j]); AC代码: #include<iostream> #include<stdio.h…
输出一个串里面能匹配的括号数 状态转移方程: if(s[i]=='('&&s[j]==')'||s[i]=='['&&s[j]==']')             dp[i][j]=dp[i+1][j-1]+2; 然后再区间合并 //#pragma comment(linker, "/STACK:167772160")//手动扩栈~~~~hdu 用c++交 #include<cstdio> #include<cstring> #i…