题目链接: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. php 不用四舍五入的方式截取小数点后两位

    /** * 字符串截取, 默认小数点后2位 * @param $money * @param int $accuracy * @return float */ private function fil ...

  2. windows2003安装证书服务:csp配置不正确、您没有此密钥容器的写访问权限

    1.填写CA名称后在生成密钥时提示:csp配置不正确或安装不完整.      原因:可能的原因为CS服务(Crysptographic Service)没有启动 . ps:该服务依赖RPC服务,但RP ...

  3. android开发之线程

              线程(android) 在java中我们学习了线程,线程,是进程的一个单位,在程序要运行时,会开启线程,运行程序,我们要创建线程就需要我们去继承接口Thread或者实现Runabl ...

  4. Nginx基本使用

    Nginx基本使用 下载源码包http://nginx.org/ http://nginx.org/en/download.html yum -y install pcre-devel openssl ...

  5. 【Codeforces715C&716E】Digit Tree 数学 + 点分治

    C. Digit Tree time limit per test:3 seconds memory limit per test:256 megabytes input:standard input ...

  6. 数据结构作业——ギリギリ eye(贪心+优先队列/贪心+并查集)

    ギリギリ eye Description A.D.1999,由坠落地球的“谜之战舰”带来的 Over Technology,揭示了人类历史和远古文明之间的丝丝联系, 促使人类终止彼此间的战争,一方面面 ...

  7. supervisord安装使用简记

    What is supervisor Supervisor is a client/server system that allows its users to monitor and control ...

  8. BZOJ2144: 跳跳棋

    传送门 神题一道. 考虑题目性质.首先对于一个状态,只存在四种情况,即最左/右边的点跳到中间,中间的点跳到左/右.而对于一个状态,显然第一种情况的两种分支不能同时存在,那么题目就可以理解为从$(a,b ...

  9. CSS line-height与vertical-align:baseline

    一.当line-height与vertical-align相遇,会发生很多匪夷所思的现象 首先,请看如下代码: <!DOCTYPE html> <html> <head& ...

  10. log4j日志工具

    一.关于日志 1.日志定义: 项目在运行阶段产生的信息 2.日志级别 最常见的日志级别有4个: error :错误日志 warn:警告日志 info:流程日志 debug:调试日志   优先级从高到低 ...