题目链接:http://poj.org/problem?id=2955

思路:括号匹配问题,求出所给序列中最长的可以匹配的长度(中间可以存在不匹配的)例如[(])]有[()]符合条件,长度为4

dp[i][j]代表从区间i到区间j所匹配的括号的最大个数,首先,假设不匹配,那么dp[i][j]=dp[i+1][j];然后查找i+1~~j有木有与第i个括号匹配的

有的话,dp[i][j]=max(dp[i][j],dp[i+1][k-1]+dp[k][j]+2).....

 #include<cstdio>
#include<iostream>
#include<algorithm>
#include<math.h>
#include<string.h>
#include<vector>
#include<queue>
#include<iterator>
#include<vector>
#include<set>
#define dinf 0x3f3f3f3f
typedef long long ll; using namespace std; char s[];
int dp[][]; int main()
{
while(scanf("%s",s+) && s[]!='e')
{
s[]=; //以下3行注意顺序
int len=strlen(s);
len--;
memset(dp,,sizeof(dp));
for(int i=len-;i>=;i--)
{
for(int j=i+;j<=len;j++)
{
dp[i][j]=dp[i+][j];
for(int k=i+;k<=j;k++)
if((s[i]=='(' && s[k]==')') || (s[i]=='[' && s[k]==']'))
dp[i][j]=max(dp[i][j],dp[i+][k-]+dp[k][j]+);
}
}
printf("%d\n",dp[][len]);
}
return ;
}

poj 2955 Brackets的更多相关文章

  1. poj 2955 Brackets dp简单题

    //poj 2955 //sep9 #include <iostream> using namespace std; char s[128]; int dp[128][128]; int ...

  2. POJ 2955 Brackets(括号匹配一)

    题目链接:http://poj.org/problem?id=2955 题目大意:给你一串字符串,求最大的括号匹配数. 解题思路: 设dp[i][j]是[i,j]的最大括号匹配对数. 则得到状态转移方 ...

  3. poj 2955 Brackets (区间dp 括号匹配)

    Description We give the following inductive definition of a “regular brackets” sequence: the empty s ...

  4. HOJ 1936&POJ 2955 Brackets(区间DP)

    Brackets My Tags (Edit) Source : Stanford ACM Programming Contest 2004 Time limit : 1 sec Memory lim ...

  5. Poj 2955 brackets(区间dp)

    Brackets Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7795   Accepted: 4136 Descript ...

  6. POJ - 2955 Brackets括号匹配(区间dp)

    Brackets We give the following inductive definition of a “regular brackets” sequence: the empty sequ ...

  7. poj 2955 Brackets (区间dp基础题)

    We give the following inductive definition of a “regular brackets” sequence: the empty sequence is a ...

  8. POJ 2955 Brackets (区间dp入门)

    Description We give the following inductive definition of a “regular brackets” sequence: the empty s ...

  9. POJ 2955 Brackets --最大括号匹配,区间DP经典题

    题意:给一段左右小.中括号串,求出这一串中最多有多少匹配的括号. 解法:此问题具有最优子结构,dp[i][j]表示i~j中最多匹配的括号,显然如果i,j是匹配的,那么dp[i][j] = dp[i+1 ...

随机推荐

  1. 解决: Sudamod/CM-13.0 源代码出现 Fatal: duplicate project .....问题

    初始化代码库的时候出现如下错误: fatal: manifest ‘default.xml‘ not available fatal: duplicate project CyanogenMod/an ...

  2. 如何根据执行计划,判断Mysql语句是否走索引

    如何根据执行计划,判断Mysql语句是否走索引

  3. 项目中CKEditor修改宽度为自适应

    项目中用到CKEditor,在config.js中直接定义config.width使得宽度无法自适应,尝试了好多次后发现了一种方法: 放弃在config.js中配置宽度 在页面检查元素,找到id为ck ...

  4. microsoft docx document operation with Java POI library

    microsoft docx document operation with Java POI library combine multiple docx document into one docu ...

  5. php 错误

    ini_set('display_errors', '1');error_reporting(E_ALL ^ E_NOTICE);   有时有了其它框架 应该用它的配置,要不然,你改了,它又改回去了: ...

  6. SDL 显示解码后的yuv12数据

    在上篇h264解码为yuv12后http://jhlong12345.blog.163.com/blog/static/1230631292015725115058709/ ,需要显示出来,使用sdl ...

  7. Debugging D Program on Windows

    http://x64dbg.com/ http://www.ollydbg.de/version2.html

  8. Q: ossfs挂载时如何设置权限?

    Q: ossfs挂载时如何设置权限? 如果要允许其他用户访问挂载文件夹,可以在运行ossfs的时候指定allow_other参数: ossfs your_bucket your_mount_point ...

  9. CentOS7下搭建邮件服务器(dovecot + postfix + SSL)

    CentOS   花了基本上两天的时间去配置CentOS7下的邮件服务器.其中艰辛太多了,一定得总结下. 本文的目的在于通过一系列配置,在CentOS 7下搭建dovecot + postfix + ...

  10. Unity3D 搭建优雅的UI框架

    为什么要使用UI框架?直接使用NGUI或UGUI一拖一拉直接搭载出界面不就行了? 我相信很多小白,包括我在刚学习Unity3D UI的时候都这样想过. 我的第一款款Unity2D游戏<山地赛车& ...