poj 2955 Brackets dp简单题
2024-09-08 00:02:01
//poj 2955
//sep9
#include <iostream>
using namespace std;
char s[128];
int dp[128][128];
int n; int rec(int l,int r)
{
if(dp[l][r]!=-1)
return dp[l][r];
if(l==r)
return dp[l][r]=0;
if(l+1==r){
if(s[l]=='('&&s[r]==')')
return dp[l][r]=2;
if(s[l]=='['&&s[r]==']')
return dp[l][r]=2;
}
int maxx=0;
if(s[l]=='('&&s[r]==')')
maxx=max(maxx,2+rec(l+1,r-1));
if(s[l]=='['&&s[r]==']')
maxx=max(maxx,2+rec(l+1,r-1));
for(int k=l;k<=r-1;++k)
maxx=max(maxx,rec(l,k)+rec(k+1,r));
return dp[l][r]=maxx;
} int main()
{
while(scanf("%s",s)==1){
if(s[0]=='e')
break;
memset(dp,-1,sizeof(dp));
n=strlen(s);
printf("%d\n",rec(0,n-1));
}
return 0;
}
最新文章
- Python-模块的使用
- MS AX 技术相关网站收藏
- treeview_dropdown_control
- 重叠(Overlapping) NAT
- JQuery 预热
- node 搭建开发框架express
- TreeSet()详解
- 爬虫框架Scrapy
- 关于SVM数学细节逻辑的个人理解(三) :SMO算法理解
- 在Winform开发框架中对附件文件进行集中归档处理
- spring中classpath
- IntelliJ IDEA 中创建maven项目
- UVALive 4725 Airport(二分)
- spring cloud配置中心属性加密处理
- tomcat如何在server.xml中配置contexts
- getParameter和getAttribute区别
- The serializable class XXX does not declare a static final serialVersionUID field of type long
- 二路归并排序java实现
- oracle判断查询结果是否为空
- MyBitis(iBitis)系列随笔之三:简单实现CRUD