POJ2955 Brackets(区间DP)
给一个括号序列,求有几个括号是匹配的。
- 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;
char str[];
int d[][];
int main(){
while(~scanf("%s",str) && str[]!='e'){
int n=strlen(str);
memset(d,,sizeof(d));
for(int len=; len<=n; ++len){
for(int i=; i+len<=n; ++i){
if(str[i]=='('&&str[i+len-]==')' || str[i]=='['&&str[i+len-]==']') d[i][i+len-]=d[i+][i+len-]+;
for(int j=; j<len-; ++j) d[i][i+len-]=max(d[i][i+len-],d[i][i+j]+d[i+j+][i+len-]);
}
}
printf("%d\n",d[][n-]);
}
return ;
}
POJ2955 Brackets(区间DP)的更多相关文章
- POJ2955 Brackets —— 区间DP
题目链接:https://vjudge.net/problem/POJ-2955 Brackets Time Limit: 1000MS Memory Limit: 65536K Total Su ...
- poj2955 Brackets (区间dp)
题目链接:http://poj.org/problem?id=2955 题意:给定字符串 求括号匹配最多时的子串长度. 区间dp,状态转移方程: dp[i][j]=max ( dp[i][j] , 2 ...
- Codeforces 508E Arthur and Brackets 区间dp
Arthur and Brackets 区间dp, dp[ i ][ j ]表示第 i 个括号到第 j 个括号之间的所有括号能不能形成一个合法方案. 然后dp就完事了. #include<bit ...
- POJ 2995 Brackets 区间DP
POJ 2995 Brackets 区间DP 题意 大意:给你一个字符串,询问这个字符串满足要求的有多少,()和[]都是一个匹配.需要注意的是这里的匹配规则. 解题思路 区间DP,开始自己没想到是区间 ...
- POJ2955:Brackets(区间DP)
Description We give the following inductive definition of a “regular brackets” sequence: the empty s ...
- CF149D. Coloring Brackets[区间DP !]
题意:给括号匹配涂色,红色蓝色或不涂,要求见原题,求方案数 区间DP 用栈先处理匹配 f[i][j][0/1/2][0/1/2]表示i到ji涂色和j涂色的方案数 l和r匹配的话,转移到(l+1,r-1 ...
- Brackets(区间dp)
Brackets Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 3624 Accepted: 1879 Descript ...
- poj 2955"Brackets"(区间DP)
传送门 https://www.cnblogs.com/violet-acmer/p/9852294.html 题意: 给你一个只由 '(' , ')' , '[' , ']' 组成的字符串s[ ], ...
- HOJ 1936&POJ 2955 Brackets(区间DP)
Brackets My Tags (Edit) Source : Stanford ACM Programming Contest 2004 Time limit : 1 sec Memory lim ...
- Code Forces 149DColoring Brackets(区间DP)
Coloring Brackets time limit per test 2 seconds memory limit per test 256 megabytes input standard ...
随机推荐
- postman导出excel出现response
https://jingyan.baidu.com/article/915fc414559b4351394b2084.html
- python-成员修饰符
python的面相对象中,拥有3个成员,字段.方法.属性 class Foo: def __init__(self,name): #公有字段name在类中与类外均能调用 self.name = nam ...
- NGUI-为Popuplist的下拉选项添加删除功能
NGUI例子里的popuplist是这样的:,但有时我们希望下拉选项都有删除功能,也就是这样:,一种方法是改popuplist的源码,我想这个实现起来不难,但现在我想说的是用反射来实现此功能,以及其他 ...
- 求:斐波那契数列的第n项
def he (n): if n < 3 : return 1 return he(n-1)+he(n-2)print(he(n))
- Linux网络运维相关
删除特殊的用户和用户组 userdel games group games 关闭不需要的服务 chkconfig chkconfig --level 345 bluetooth off 删减系 ...
- python与MySQL数据库
python与MySQL数据库 慕课网连接 我使用的软件:python2.7 + MySQL+ Navicat for MySQL + Atom 注意:你的数据库表格类型的引擎为:InnoDB :字符 ...
- 【转】Unity3D Transform中有关旋转的属性和方法测试
Transform有关旋转个属性和方法测试 一,属性 1,var eulerAngles : Vector3 public float yRotation = 5.0F; void Update() ...
- 【bzoj3638】Cf172 k-Maximum Subsequence Sum 模拟费用流+线段树区间合并
题目描述 给一列数,要求支持操作: 1.修改某个数的值 2.读入l,r,k,询问在[l,r]内选不相交的不超过k个子段,最大的和是多少. 输入 The first line contains inte ...
- [bzoj1798][Ahoi2009]Seq 维护序列seq ([洛谷P3373]【模板】线段树 2)
题目大意:有$n$个数,有$m$个操作,有三种: $1\;l\;r\;x:$把区间$[l,r]$内的数乘上$x$ $2\;l\;r\;x:$把区间$[l,r]$内的数加上$x$ $3\;l\;r:$询 ...
- async-http
android-async-http开源框架可以是我们轻松的获取网络数据或者向服务器发送数据,使用起来也很简单,下面做简单介绍,具体详细使用看官网:https://github.com/loopj/a ...