POJ-2955-Brackets
来源:互联网 发布:淘宝最靠谱的aj店 编辑:程序博客网 时间:2024/06/03 19:21
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 i1, i2, …, imwhere 1 ≤ i1 < i2 < … < im ≤ n, ai1ai2 … 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 个括号的最大匹配数目
那么如果第i个和第j个是一对匹配的括号那么dp[i][j] = dp[i+1][j-1]+2;
dp[i][j] = max(dp[i][j], dp[i][k]+dp[k+1][j]);
dp[][]的MAX开到120就够了,太大会T掉 ,QAQ
- DP poj 2955 Brackets
- poj 2955 brackets
- POJ 2955 Brackets
- POJ 2955 Brackets
- POJ 2955 Brackets
- poj 2955 Brackets
- POJ 2955 Brackets
- POJ 2955 Brackets
- poj 2955 Brackets
- POJ 2955 Brackets
- POJ 2955:Brackets
- POJ 2955 Brackets
- POJ 2955 brackets
- POJ 2955 Brackets
- POJ 2955 Brackets
- Brackets (poj 2955)
- poj 2955 Brackets
- POJ 2955 Brackets (基础)
- IPC 信号量(semaphore)
- C++ 共用体 枚举 结构体 介绍
- JSP 弹出对话框的方式总结
- MyBatis插入单条数据
- (null) entry in command string: null chmod 0700的解决方法
- POJ-2955-Brackets
- [学习笔记]Android RecyclerView
- 弱网测试
- centos 部署 tomcat 指定 jre版本
- 将RGB颜色转换成16bit颜色
- Spring 注入 Map
- 【设计模式】—— 装饰模式Decorator
- 设计模式之建造者模式
- 在java中assert有什么作用?