SCU 1069 POJ 2955 Brackets
区间DP
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std; char s[];
int dp[][]; int main()
{
int i,j,k;
while(~scanf(" %s",s))
{
if(strcmp(s,"end")==) break;
int len=strlen(s);
for(i=len-; i>=; i--) s[i+]=s[i];
memset(dp,,sizeof(dp)); for(i=; i<=len; i++) //长度
{
for(j=; j<=len; j++) //起点
{
int w=i+j-;//终点
if(w<=j||w>len) continue;
if((s[j]=='('&&s[w]==')')||(s[j]=='['&&s[w]==']'))
dp[j][w]=dp[j+][w-]+;
for(k=j; k<w; k++)
dp[j][w]=max(dp[j][w],dp[j][k]+dp[k+][w]);
}
}
printf("%d\n",dp[][len]);
}
return ;
}
SCU 1069 POJ 2955 Brackets的更多相关文章
- poj 2955 Brackets dp简单题
//poj 2955 //sep9 #include <iostream> using namespace std; char s[128]; int dp[128][128]; int ...
- poj 2955 Brackets
题目链接:http://poj.org/problem?id=2955 思路:括号匹配问题,求出所给序列中最长的可以匹配的长度(中间可以存在不匹配的)例如[(])]有[()]符合条件,长度为4 dp[ ...
- POJ 2955 Brackets(括号匹配一)
题目链接:http://poj.org/problem?id=2955 题目大意:给你一串字符串,求最大的括号匹配数. 解题思路: 设dp[i][j]是[i,j]的最大括号匹配对数. 则得到状态转移方 ...
- poj 2955 Brackets (区间dp 括号匹配)
Description We give the following inductive definition of a “regular brackets” sequence: the empty s ...
- HOJ 1936&POJ 2955 Brackets(区间DP)
Brackets My Tags (Edit) Source : Stanford ACM Programming Contest 2004 Time limit : 1 sec Memory lim ...
- Poj 2955 brackets(区间dp)
Brackets Time Limit: 1000MS Memory Limit: 65536K Total Submissions: 7795 Accepted: 4136 Descript ...
- POJ - 2955 Brackets括号匹配(区间dp)
Brackets We give the following inductive definition of a “regular brackets” sequence: the empty sequ ...
- poj 2955 Brackets (区间dp基础题)
We give the following inductive definition of a “regular brackets” sequence: the empty sequence is a ...
- POJ 2955 Brackets (区间dp入门)
Description We give the following inductive definition of a “regular brackets” sequence: the empty s ...
随机推荐
- Oracle数据库创建数据库实例1
http://jingyan.baidu.com/article/ae97a646d128d5bbfd461d00.html
- Hbulider里面template模板自用
template.js 一款 JavaScript 模板引擎,简单,好用.提供一套模板语法,用户可以写一个模板区块,每次根据传入的数据,生成对应数据产生的HTML片段,渲染不同的效果. 特性: 模版编 ...
- iOS 如何随意的穿插跳跃,push来pop去
OS 如何随意的穿插跳跃,push来pop去 主题思想:如A.B.C.D 四个视图控制器 想要在 A push B 后, B 在push 到 D ,然后从 D pop 到 C ,在从 C pop 的A ...
- {java学习}[第一章]软件开发概述(2017.1.11).
- asp.net 后台验证成功(弹出对话框)并跳转?不能实现
原始 Context.Response.Write("<script></script>"); Response.Redirect(); 解决办法: Cli ...
- IOS APP 国际化(实现不跟随系统语言,不用重启应用,代码切换stroyboard ,xib ,图片,其他资源)
http://www.cnblogs.com/tangbinblog/p/3898046.html
- winform上传文件
//上传图片 文件 public int addUpPic( String strProCode,String strFileName,String strUpType) { //strFileNam ...
- SQLite学习网址
http://www.runoob.com/sqlite/sqlite-data-types.html
- PAT 团体程序设计天梯赛-练习集 L2-009. 抢红包
没有人没抢过红包吧…… 这里给出N个人之间互相发红包.抢红包的记录,请你统计一下他们抢红包的收获. 输入格式: 输入第一行给出一个正整数N(<= 104),即参与发红包和抢红包的总人数,则这些人 ...
- c# socket传输struct类型
data结构体类型 public struct datas { public string test1; public string test2; } //socket服务器端 publi ...