Brackets POJ - 2955
解法
区间dp例题,每次枚举分段点的时候先更新如果开始到结束区间端点有闭合的括号,那么dp[start][end]=dp[start+1][end-1]+2其他照常枚举即可
代码
#include <iostream>
#include <cstring>
using namespace std;
int dp[666][666];
int main()
{
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
string a;
while(cin>>a)
{
if(a[0]=='e')
break;
memset(dp,0,sizeof(dp));
for(int i=1;i<=a.size();i++)
for(int j=0;j<a.size();j++)
{
int end=i+j-1;
if(end>a.size()-1)
continue;
if((a[j]=='('&&a[end]==')')||(a[j]=='['&&a[end]==']'))
dp[j][end]=dp[j+1][end-1]+2;
for(int k=j;k<end;k++)
dp[j][end]=max(dp[j][end],dp[j][k]+dp[k+1][end]);
}
cout<<dp[0][a.size()-1]<<"\n";
}
}
Brackets POJ - 2955的更多相关文章
- (区间dp 或 记忆化搜素 )Brackets -- POJ -- 2955
http://poj.org/problem?id=2955 Description We give the following inductive definition of a “regular ...
- A - Brackets POJ - 2955 (区间DP模板题)
题目链接:https://cn.vjudge.net/contest/276243#problem/A 题目大意:给你一个字符串,让你求出字符串的最长匹配子串. 具体思路:三个for循环暴力,对于一个 ...
- 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)
http://poj.org/problem?id=2955 题意:给出一串字符,求括号匹配的数最多是多少. 思路:区间DP. 对于每个枚举的区间边界,如果两边可以配对成括号,那么dp[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 ...
随机推荐
- SCUT - 240 - 宝华的文件系统 - 模拟
https://scut.online/p/240 就是要小心绝对路径中也有.和..出现. #include<bits/stdc++.h> using namespace std; #de ...
- 洛谷 - P2602 - 数字计数 - 数位dp
https://www.luogu.org/problemnew/show/P2602 第二道数位dp,因为“数位dp都是模板题”(误),所以是从第一道的基础上面改的. 核心思想就是分类讨论,分不同情 ...
- Codeforces Round #408 (Div. 2) D
Description Inzane finally found Zane with a lot of money to spare, so they together decided to esta ...
- cpp extern 关键字用法
语法说明: extern 可以置于变量或者函数前,以标示变量或者函数的在别的文件中定义,提示编译器遇到此变量和函数后,在其他模块中寻找其定义.此外extern也可用来进行链接指定. 即 extern ...
- RHEL 6.5----rsync+inotify数据同步服务
Rsync特性: 可以镜像保存整个目录树和文件系统: 可以保持原文件的权限.时间.软硬链接等: 安装简单. 传输特点: 速度快:rsync首次同步会复制同步全部内容,以后只传输修改过的文件: 压缩传输 ...
- Windows下Apache应用环境塔建安全设置(目录权限设置)
目的:为Apache,php配置受限制的用户权限.保护系统安全.需要的朋友可以参考下. 环境配置情况: apache安装目录:d:\www-s\apache php目录:d:\www-s\php5 m ...
- 项目错误提示Multiple markers at this line
新安装个Myeclipse,导入以前做的程序后程序里好多错,第一行提示: Multiple markers at this line - The type java.lang.Obje ...
- Spring Boot整合Spring Batch
引言 Spring Batch是处理大量数据操作的一个框架,主要用来读取大量数据,然后进行一定的处理后输出指定的形式.比如我们可以将csv文件中的数据(数据量几百万甚至几千万都是没问题的)批处理插入保 ...
- servlet上传文件+上传进度显示
效果图 功能描述 1.使用jquery.form.js实现异步上传功能,并显示上传进度 2.servlet中保存上传的文件到指定文件夹 3.查看已经上传的文件 4.不同文件类型用不同图标显示 下载 h ...
- position 位置、表单
一.position 位置 1.只要使用了定位,必须有一个相对的参照物 2.具体定位的那个元素需加position:absolute:(绝对的) 绝对的:就是具体到某一个地方,特别详细的意思 ...