区间DP

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std; char s[];
int dp[][]; int main()
{
int i,j,k;
while(~scanf(" %s",s))
{
if(strcmp(s,"end")==) break;
int len=strlen(s);
for(i=len-; i>=; i--) s[i+]=s[i];
memset(dp,,sizeof(dp)); for(i=; i<=len; i++) //长度
{
for(j=; j<=len; j++) //起点
{
int w=i+j-;//终点
if(w<=j||w>len) continue;
if((s[j]=='('&&s[w]==')')||(s[j]=='['&&s[w]==']'))
dp[j][w]=dp[j+][w-]+;
for(k=j; k<w; k++)
dp[j][w]=max(dp[j][w],dp[j][k]+dp[k+][w]);
}
}
printf("%d\n",dp[][len]);
}
return ;
}

SCU 1069 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 思路:括号匹配问题,求出所给序列中最长的可以匹配的长度(中间可以存在不匹配的)例如[(])]有[()]符合条件,长度为4 dp[ ...

  3. POJ 2955 Brackets(括号匹配一)

    题目链接:http://poj.org/problem?id=2955 题目大意:给你一串字符串,求最大的括号匹配数. 解题思路: 设dp[i][j]是[i,j]的最大括号匹配对数. 则得到状态转移方 ...

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

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

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

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

  6. Poj 2955 brackets(区间dp)

    Brackets Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 7795   Accepted: 4136 Descript ...

  7. POJ - 2955 Brackets括号匹配(区间dp)

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

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

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

  9. POJ 2955 Brackets (区间dp入门)

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

随机推荐

  1. hadoop操作

    常用命令: https://hadoop.apache.org/docs/r1.0.4/cn/hdfs_shell.html ls命令 /usr/bin/hadoop/software/hadoop/ ...

  2. spring security:ajax请求的session超时处理

    当前端在用ajax请求时,如果没有设置session超时时间并且做跳转到登录界面的处理,那么只是靠后台是很难完成超时的一系列动作的:但是如果后台 没有封装一个ajax请求公共类,那么在ajax请求上下 ...

  3. 新服务器sudo与权限分配<NIOT>

    0,生成RSA公钥秘钥 a,源主机:#ssh-keygen -t rsa 1,拷贝公钥到authorized_keys文件里面 a,源主机:#ssh-copy-id -i /root/.ssh/id_ ...

  4. 打印机服务器搭建 -cups

    系统:ubuntu 14.04 http://foo2zjs.rkkda.com/INSTALL 安装cups   sudo apt-get install cups 安装完成后,把打印机的数据线与服 ...

  5. 3.Thread中的静态方法

    1.currentThread() public class Thread14 extends Thread{ static { System.out.println("静态块的打印:&qu ...

  6. vsphere安装虚拟机

    新建虚拟机完成后,启动虚拟机,打开启动虚拟机控制台,选择CD/DVD驱动器 选择iso镜像,可以是本地或存储中心的iso,选择后点击虚拟机--客户机--发送Ctrl+Alt+Del,接下来就是正常的操 ...

  7. 自定义GridLayout实现条目的拖动动画特效

    1.自定义GridLayout实现增加条目过度动画操作 public class MyGridLayout extends GridLayout { public MyGridLayout(Conte ...

  8. 分布式版本控制系统Git-----3.图形化Tortoisegit创建本地库并且提交到远程服务器上

    [前提你已经有了自己的远程仓库帐号密码和HTTP地址] PS:图形化会方便,但是个人认为还是敲命令比较好,会锻炼人的思维和逻辑. 1.首先在任意一个地方创建test目录.若要把test目录放在Git的 ...

  9. JavaScript中的window对象

    JavaScript中的window对象:http://www.cnblogs.com/kissdodog/archive/2013/01/01/2841464.html

  10. Apache Http Server和Tomcat 之区别

    转自:Apache Http Server和Tomcat 之区别 Apache官方网站:http://www.apache.org/Tomcat官方网站:http://tomcat.apache.or ...