poj 2955 Brackets
题目链接: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的更多相关文章
- 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 题目大意:给你一串字符串,求最大的括号匹配数. 解题思路: 设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 ...
- POJ 2955 Brackets --最大括号匹配,区间DP经典题
题意:给一段左右小.中括号串,求出这一串中最多有多少匹配的括号. 解法:此问题具有最优子结构,dp[i][j]表示i~j中最多匹配的括号,显然如果i,j是匹配的,那么dp[i][j] = dp[i+1 ...
随机推荐
- Go语言总结(图片打开略慢请知晓)
- 结构体里的“位域”(bit-field)结构
首先看一个题目: #include <iostream> using namespace std; #include <string.h> typedef struct AA{ ...
- iOS地图 -- 区域监听的实现和小练习
区域监听用到的方法 [self.mgr startMonitoringForRegion:region]; --> 开启区域监听,没有返回值,在代理方法中得到信息并且处理信息 注:该方法只有用户 ...
- 解决:sudo: 无法解析主机:dinphy-500-310cn: 连接超时
出现这种问题是hosts文件没有配置好所导致的,linux无法解析到您的主机地址,解决方案如下: sudo vim /etc/hosts 其中vim是你的文本编辑器的命令,你如果电脑中没有vim,用g ...
- 【整理】认识MSG结构体
在Windows程序中,消息是由MSG结构体来表示的.MSG结构体的定义如下(参见MSDN): typedef struct tagMSG { HWND hwnd; UINT message; WPA ...
- Google 地图 API V3 之事件
Google官方教程: Google 地图 API V3 使用入门 Google 地图 API V3 针对移动设备进行开发 Google 地图 API V3 之事件 Google 地图 API V3 ...
- 修改Excel2013默认模版(启动模版和新建Sheet模版)
1. C:\Windows\ShellNew\EXCEL12.XLSX 设置好格式后另存为, 然后复制过来覆盖掉,如果覆盖不了,注意修改所有者权限 2. 新建文件保存为模版文件Sheet.xltx, ...
- Instant Radiosity实现
本来说等把课程作业做完再来弄这个,但是还是没有忍住,先做了,主要原因还是这个算法很容易实现.这个算法在1997年由Keller首次提出.虽然名字叫Instant Radiosity,但是它和Radio ...
- C++变参数模板和...操作符
https://en.wikipedia.org/wiki/Variadic_template https://msdn.microsoft.com/en-us/library/dn439779.as ...
- win10如何100%提升网络速度
1.Win+R运行,输入gpedit.msc 2.依次打开"计算机配置"-"管理模板"-"网络"-"QoS数据包计划程序" ...