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 ...
随机推荐
- 算法学习--Day3
今天搞了一波算法的哈希,代码难道不大,记录在这里吧. 题目描述 “臭味相投”——这是我们描述朋友时喜欢用的词汇.两个人是朋友通常意味着他们存在着许多共同的兴趣.然而作为一个宅男,你发现自己与他 ...
- poj 3734 Blocks【指数型生成函数】
指数型生成函数,推一推可得: \[ (1+\frac{x^1}{1!}+\frac{x^2}{2!}+\frac{x^3}{3!}+...)^2+(1+\frac{x^2}{2!}+\frac{x^4 ...
- 洛谷 P2296 寻找道路【bfs+spfa】
反向建边bfs出不能到t的点,然后对每个能到这些点的点打上del标记,然后spfa的时候不经过这些点即可 #include<iostream> #include<cstdio> ...
- UVA - 10564 Paths through the Hourglass
传送门:https://vjudge.net/problem/UVA-10564 题目大意:给你一张形如沙漏一般的图,每一个格子有一个权值,问你有多少种方案可以从第一行走到最后一行,并且输出起点最靠前 ...
- 521 Longest Uncommon Subsequence I 最长特殊序列 Ⅰ
给定两个字符串,你需要从这两个字符串中找出最长的特殊序列.最长特殊序列定义如下:该序列为某字符串独有的最长子序列(即不能是其他字符串的子序列).子序列可以通过删去字符串中的某些字符实现,但不能改变剩余 ...
- Backbone学习记录(7)
事件委托 <form> <input type="text" class="txt"> <input type="but ...
- Ionic之增加样式会自动换行解决方案
设置样式的时候,引用自身的样式,能正常显示,但是引用自定义样式显示的时候,竟然或自动换行,好尴尬. 原本代码: $('.codeSuccess').css({'display':'block'}); ...
- LN : leetcode 733 Flood Fill
lc 733 Flood Fill 733 Flood Fill An image is represented by a 2-D array of integers, each integer re ...
- [ AHOI 2013 ] 作业 & [ BZOJ 3809 ] Gty的二逼妹子序列
\(\\\) Description 给出一个长为 \(n\) 的数列 \(A\) 和 \(k\),多次询问: 对于一个区间 \([L_i,R_i]\),问区间内有多少个数在 \([a_i,b_i]\ ...
- CSS3常用属性浏览器兼容前缀
1.检测网站https://gsnedders.html5.org/outliner/ 2.查询是否支持前缀http://caniuse.com 3.border-radius\box-shadow\ ...