/**
POJ 2955 Brackets
区间dp
*/
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cstring>
#define ll long long
#define maxn 105
using namespace std;
int dp[maxn][maxn];
char s[maxn];
int dfs(int l,int r){
if(l>=r) return 0;
if(dp[l][r] != -1) return dp[l][r];
if(s[l]=='('&&s[r]==')'||s[l]=='['&&s[r]==']')
dp[l][r]=dfs(l+1,r-1)+2;
for(int i=l;i<r;i++)
dp[l][r]=max(dp[l][r],dfs(l,i)+dfs(i+1,r));
return dp[l][r];
}
int main(){
int n;
while(~scanf("%s",s)&&s[0]!='e'){
int n=strlen(s);
memset(dp,-1,sizeof(dp));
int ans=dfs(0,n-1);
printf("%d\n",ans);
}
return 0;
}
POJ 2955 Brackets
最新推荐文章于 2020-06-03 17:42:50 发布