SCU 1069 POJ 2955 Brackets
区间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的更多相关文章
- 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 括号匹配)
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 ...
随机推荐
- 基于clip-path的任意元素的碎片拼接动效(源自鑫空间)
一.实现原理. 效果本质上是CSS3动画,就是旋转transform:rotate和位移:transform:translate,只是旋转和位移的部件是三角碎片而已.三角是使用CSS3 clip-pa ...
- js 的四种设计模式的优缺点
原始模式: var Car = new Object; Car.color = "blue"; Car.door = 4; Car.showColor = function() { ...
- python join()阻塞的用法
join()阻塞的用法,用来检测线程有没有完全执行完毕 #!/usr/bin/env python#-*- coding:utf-8 -*-import threadingimport time de ...
- sql server 2012提示评估期已过的解决办法 附序列号
sql server 2012提示评估期已过的解决方法: 第一步:进入SQL2012配置工具中的安装中心. 第二步:再进入左侧维护选项界面,然后选择选择版本升级. 第三步:进入输入产品密钥界面,输入相 ...
- ModelDriven
功能: submit 之后显示结果 1.项目结构 2.web.xml <?xml version="1.0" encoding="UTF-8"?> ...
- Asp.net MVC 单元测试 简要笔记
首先要啰嗦几句. 单元测试是TDD的重要实践方法,也是代码质量的一种保证手段.在项目的工程化开发中,研发人员应该尽量保证书写Unit Test,即使不使用TDD. (VS中,我们可以直接使用微软提供的 ...
- 分布式版本控制系统Git-----2.上传至远程仓库之基础版
好,之前已经将文档下载下来了,但是我感觉还是将自己之前截的图放出来比较好,自己整理的,但是总不能放桌面上,时间久了也会忘得,索性放到博客上吧,也便于其他人查看,简直是百利而无一害啊.哈哈.来吧. 注意 ...
- module parameters
Parameter values can be assigned at load time by insmod or modprobe(this can read parameter from con ...
- Oracle第二天
Oracle第二天 整体安排(3天) 第一天:Oracle的安装配置(服务端和客户端),SQL增强(单表查询). 第二天:SQL增强(多表查询.子查询.伪列-分页),数据库对象(表.约束.序列),Or ...
- hdu 1384 Intervals
差分约束系统. 求最小值,用最长路来解决. #include<cstdio> #include<cstring> #include<cmath> #include& ...