博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj2955Brackets(区间DP)
阅读量:5989 次
发布时间:2019-06-20

本文共 1741 字,大约阅读时间需要 5 分钟。

Description

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

  • the empty sequence is a regular brackets sequence,
  • if s is a regular brackets sequence, then (s) and [s] are regular brackets sequences, and
  • if a and b are regular brackets sequences, then ab is a regular brackets sequence.
  • no other sequence is a regular brackets sequence

For instance, all of the following character sequences are regular brackets sequences:

(), [], (()), ()[], ()[()]

while the following character sequences are not:

(, ], )(, ([)], ([(]

Given a brackets sequence of characters a1a2 … an, your goal is to find the length of the longest regular brackets sequence that is a subsequence of s. That is, you wish to find the largest m such that for indices i1i2, …, im where 1 ≤ i1 < i2 < … < im ≤ nai1ai2 … aim is a regular brackets sequence.

Given the initial sequence ([([]])], the longest regular brackets subsequence is [([])].

Input

The input test file will contain multiple test cases. Each input test case consists of a single line containing only the characters ()[, and ]; each input test will have length between 1 and 100, inclusive. The end-of-file is marked by a line containing the word “end” and should not be processed.

Output

For each input case, the program should print the length of the longest possible regular brackets subsequence on a single line.

Sample Input

((()))()()()([]]))[)(([][][)end

Sample Output

66406
dp[i][j]表示在区间i到j匹配的最大数。

 
#include
#include
int max(int a,int b){ return a>b?a:b;}int main(){ int dp[105][105]; char str[105]; while(scanf("%s",str)>0&&strcmp(str,"end")!=0) { int len=strlen(str); memset(dp,0,sizeof(dp)); for(int l=1;l

转载地址:http://dunlx.baihongyu.com/

你可能感兴趣的文章
IOS-通讯录
查看>>
通讯录——数据结构课设
查看>>
ENVI【非监督分类】
查看>>
Hive深入浅出
查看>>
uva 1594 Ducci Sequence <queue,map>
查看>>
40、JDBC相关概念介绍
查看>>
unix
查看>>
Spring Boot MyBatis 通用Mapper插件集成
查看>>
testNg vs junit 4.X @Test
查看>>
微信公众号用户OpenID同步导出系统
查看>>
如何自定义 maven中的archetype
查看>>
使用bitmap处理海量数据
查看>>
(转)Bootstrap 之 Metronic 模板的学习之路 - (5)主题&布局配置
查看>>
初学JavaScript之推測new操作符的原理
查看>>
MyBatis入门程序之整合Spring
查看>>
CommonClassLoader或SharedClassLoader加载的Spring如何访问并不在其加载范围内的用户程序呢...
查看>>
【Java学习笔记之六】java三种循环(for,while,do......while)的使用方法及区别
查看>>
微软 改变 开源【几个站点】
查看>>
html-webpack-plugin插件 根据模板生成多页面
查看>>
webApi文档好帮手-apidoc使用教程
查看>>