输出一个串里面能匹配的括号数

状态转移方程:

if(s[i]=='('&&s[j]==')'||s[i]=='['&&s[j]==']')
             dp[i][j]=dp[i+1][j-1]+2;

然后再区间合并

 //#pragma comment(linker, "/STACK:167772160")//手动扩栈~~~~hdu 用c++交
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<iostream>
#include<queue>
#include<stack>
#include<cmath>
#include<set>
#include<algorithm>
#include<vector>
// #include<malloc.h>
using namespace std;
#define clc(a,b) memset(a,b,sizeof(a))
#define LL long long
const int inf = 0x3f3f3f3f;
const double eps = 1e-;
const double pi = acos(-);
// inline int r(){
// int x=0,f=1;char ch=getchar();
// while(ch>'9'||ch<'0'){if(ch=='-') f=-1;ch=getchar();}
// while(ch>='0'&&ch<='9'){x=x*10+ch-'0';ch=getchar();}
// return x*f;
// }
int dp[][];
char s[];
int main(){
// freopen("in.txt","r",stdin);
while(gets(s)!=NULL){
if(s[]=='e') break;
// cout<<s<<endl;
int len=strlen(s);
clc(dp,);
for(int i=len-;i>=;i--){
for(int j=i+;j<len;j++){
if(s[i]=='('&&s[j]==')'||s[i]=='['&&s[j]==']')
dp[i][j]=dp[i+][j-]+;
for(int k=i;k<j;k++)//区间合并
dp[i][j]=max(dp[i][j],dp[i][k]+dp[k+][j]);
}
}
printf("%d\n",dp[][len-]);
}
return ;
}

POJ 2955 Brackets 区间合并的更多相关文章

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

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

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

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

  3. POJ 2955 Brackets 区间DP 入门

    dp[i][j]代表i->j区间内最多的合法括号数 if(s[i]=='('&&s[j]==')'||s[i]=='['&&s[j]==']') dp[i][j] ...

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

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

  5. poj 2955"Brackets"(区间DP)

    传送门 https://www.cnblogs.com/violet-acmer/p/9852294.html 题意: 给你一个只由 '(' , ')' , '[' , ']' 组成的字符串s[ ], ...

  6. POJ 2955 Brackets(区间DP)

    题目链接 #include <iostream> #include <cstdio> #include <cstring> #include <vector& ...

  7. POJ 2955 Brackets 区间DP 最大括号匹配

    http://blog.csdn.net/libin56842/article/details/9673239 http://www.cnblogs.com/ACMan/archive/2012/08 ...

  8. POJ 2995 Brackets 区间DP

    POJ 2995 Brackets 区间DP 题意 大意:给你一个字符串,询问这个字符串满足要求的有多少,()和[]都是一个匹配.需要注意的是这里的匹配规则. 解题思路 区间DP,开始自己没想到是区间 ...

  9. poj 2955 Brackets 括号匹配 区间dp

    题意:最多有多少括号匹配 思路:区间dp,模板dp,区间合并. 对于a[j]来说: 刚開始的时候,转移方程为dp[i][j]=max(dp[i][j-1],dp[i][k-1]+dp[k][j-1]+ ...

随机推荐

  1. python参考手册--第8章

    1.模块和import (1)首次import module会做以下3件事: a)创建新的命名空间,用作在该源文件中定义的所有对象的容器.在模块中定义的函数和方法在使用global语句时将访问该命名空 ...

  2. spring <form:checkboxes> tag and css class

    I have issue with: <form:checkboxes path="roles" cssClass="checkbox" items=&q ...

  3. C++ 嵌套类使用(一)

    一.嵌套类 在一个类的内部定义另一个类,我们称之为嵌套类(nested class),或者嵌套类型.之所以引入这样一个嵌套类,往往是因为外围类需要使用嵌套类对象作为底层实现,并且该嵌套类只用于外围类的 ...

  4. CSU1326+背包+并查集

    先预处理出有多少个任务即可 #include<stdio.h> #include<stdlib.h> #include<string.h> #include< ...

  5. Android 调用系统的拍相程序进行录像

    xml: <?xml version="1.0" encoding="utf-8"?> <LinearLayout xmlns:android ...

  6. vim查找/替换字符串 及一些高级用法

    例: 32 ./run 0_39.pkt 0_39.jpg 33 ./run 0_3.pkt 0_3.jpg 34 ./run 0_40.pkt 0_40.jpg 35 ./run 0_41.pkt ...

  7. QGraphicsEffect介绍(十分漂亮)

    原文链接:Qt 图形特效(Graphics Effect)介绍 QGraphicsEffect也是Qt-4.6引入的一个新功能.它让给图形元素QGraphicsItem增加更佳视觉效果的编程变得非常简 ...

  8. Retrofit初识

    Retrofit Retrofit是一套RESTful架构的Android(Java)客户端实现,基于注解,提供JSON to POJO(Plain Ordinary Java Object,简单Ja ...

  9. 精选7款绚丽的HTML5和jQuery图片动画特效

    在HTML5出现后,图片就变得更加富有动感了,各种图片动画特效也层出不穷,例如图片播放器.图片导航.3D图片动画等等.本文将精选几款具有代表性的HTML5和jQuery图片动画特效,绚丽的画面.实用的 ...

  10. clone函数

    http://blog.csdn.net/caianye/article/details/5947282 http://wenku.baidu.com/link?url=qnq7laYDYm1V8tl ...