题意很简单,就是求给出串中最大的括号匹配数目.基础题,格式基本为简单区间dp模板. #include<iostream> #include<string.h> using namespace std; ]; ][]; int pd(int x,int y) { ; ; ; } int main() { int n,i,j,k,l,s; while(cin>>a) { //cout<<a<<endl; n=strlen(a); ]==; memse…
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…
题目链接:https://vjudge.net/problem/POJ-2955 Brackets Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 9630   Accepted: 5131 Description We give the following inductive definition of a “regular brackets” sequence: the empty sequence is a regu…
题目链接:http://poj.org/problem?id=2955 题意:给定字符串 求括号匹配最多时的子串长度. 区间dp,状态转移方程: dp[i][j]=max ( dp[i][j] , 2+dp[i+1][k-1]+dp[k+1][j] ); 代码: #include<iostream> #include<cstdio> #include<algorithm> #include<cstring> using namespace std; #def…
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…
Arthur and Brackets 区间dp, dp[ i ][ j ]表示第 i 个括号到第 j 个括号之间的所有括号能不能形成一个合法方案. 然后dp就完事了. #include<bits/stdc++.h> #define LL long long #define fi first #define se second #define mk make_pair #define PLL pair<LL, LL> #define PLI pair<LL, int>…
POJ 2995 Brackets 区间DP 题意 大意:给你一个字符串,询问这个字符串满足要求的有多少,()和[]都是一个匹配.需要注意的是这里的匹配规则. 解题思路 区间DP,开始自己没想到是区间DP,以为就是用栈进行模拟呢,可是发现就是不大对,后来想到是不是使用DP,但是开始的时候自己没有推出递推关系,后来实在想不出来看的题解,才知道是区间DP,仔细一想确实是啊. 下面就是状态转移方程: \[ \begin{cases}dp[i][j] &=& dp[i+1][j-1]+if(str…
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…
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…
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…