题解【POJ2955】Brackets】的更多相关文章

题目链接: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 这题要求求出一段括号序列的最大括号匹配数量 规则如下: 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 sequences, th…
Brackets Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 8716   Accepted: 4660 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…
题目链接: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…
取血怒.first blood,第一区间DP,这样第一次没有以某种方式在不知不觉中下降~~~ 题目尽管是鸟语.但还是非常赤裸裸的告诉我们要求最大的括号匹配数.DP走起~ dp[i][j]表示区间[i,j]的最大匹配数.那么最重要的状态转移方程就是: dp[i][j]=max(dp[i][k]+dp[k+1][j]) 对啦,要先初始化边界啊.两步走~: memset(dp,0,sizeof dp); if str[i]==str[i+1]   则:dp[i][i+1]=2       请看----…
给一个括号序列,求有几个括号是匹配的. dp[i][j]表示序列[i,j]的匹配数 dp[i][j]=dp[i+1][j-1]+2(括号i和括号j匹配) dp[i][j]=max(dp[i][k]+dp[k+1][j])(i<=k<j) #include<cstdio> #include<cstring> #include<algorithm> using namespace std; ]; ][]; int main(){ ]!='e'){ int n=s…
很好的区间DP题. 需要注意第一种情况不管是否匹配,都要枚举k来更新答案,比如: "()()()":dp[0][5]=dp[1][4]+2=4,枚举k,k=1时,dp[0][1]+dp[2][5]=6,最后取最大值6. 第一层d相当于"长度"的含义,第二层枚举i,j就可以用i+d表示,通过这种方式枚举区间左右端点. 1 #include<cstdio> 2 #include<cstdlib> 3 #include<cstring>…
一.数位DP 1.含有或不含某个数“xx”: HDU3555 Bomb HDU2089 不要62 2.满足某些条件,如能整除某个数,或者数位上保持某种特性: HDU3652 B-number CodeForces - 55D Beautiful numbers POJ3252 Round Numbers HDU3709 Balanced Number 二.区间DP: 1.由小区间往左右两边扩散: POJ3186 Treats for the Cows ZOJ3469 Food Delivery…
马上区域赛,发现DP太弱,赶紧复习补上. #普通DP CodeForces-546D Soldier and Number Game 筛法+动态规划 待补 UVALive-8078 Bracket Sequence 问以每个字符为左端点的最长括号序列是多长.(包括尖.花.中小括号) 状态:设dp[i]为从i开始的括号序列最长长度. 转移:以i+1为起点的最长串后边的字符若与左括号匹配,答案是加上这个字符后边的最长串,否则为零. HDU-1024 Max Sum Plus Plus 给一个序列,找…
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…