博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
poj 2955 Brackets(区间DP,经典问题)求有规律的括号的最大长度
阅读量:4036 次
发布时间:2019-05-24

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

1、

2、题目大意

给出一个只包含()[]的字符序列,求出该字符序列中有规律的符号序列的最长长度

有规律的序列要求如下:

  • 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, thenab is a regular brackets sequence.
  • no other sequence is a regular brackets sequence

dp[i][j]表示i到j区间有规律字符串的最大长度

dp[i][j]=max(dp[i][j],dp[i][k]+dp[k][j])其中i=<k<j

3、AC代码:

#include
#include
#include
using namespace std;#define N 105char str[N];int dp[N][N];int check(char a,char b){ if((a=='(' && b==')') || (a=='[' && b==']')) return 1; return 0;}int main(){ while(scanf("%s",str)!=EOF) { if(strcmp(str,"end")==0) break; int len=strlen(str); memset(dp,0,sizeof(dp)); for(int i=0;i

 

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

你可能感兴趣的文章
机器学习实战之决策树二
查看>>
[LeetCode By Python]7 Reverse Integer
查看>>
[leetCode By Python] 14. Longest Common Prefix
查看>>
[leetCode By Python]111. Minimum Depth of Binary Tree
查看>>
[LeetCode By Python]118. Pascal's Triangle
查看>>
[LeetCode By Python]121. Best Time to Buy and Sell Stock
查看>>
[LeetCode By Python]122. Best Time to Buy and Sell Stock II
查看>>
[LeetCode By Python]125. Valid Palindrome
查看>>
[LeetCode By Python]136. Single Number
查看>>
[LeetCode By MYSQL] Combine Two Tables
查看>>
python jieba分词模块的基本用法
查看>>
[CCF BY C++]2017.12 最小差值
查看>>
[CCF BY C++]2017-12 游戏
查看>>
如何打开ipynb文件
查看>>
[Leetcode BY python ]190. Reverse Bits
查看>>
Android下调用收发短信邮件等(转载)
查看>>
Android中电池信息(Battery information)的取得
查看>>
SVN客户端命令详解
查看>>
Android/Linux 内存监视
查看>>
Linux系统信息查看
查看>>