#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<cmath>
#include<algorithm>
using namespace std;
const int maxn = 105;
int dp[maxn][maxn];
bool match(char x,char y)
{
if(x=='(' && y==')') return true;
if(x=='[' && y==']') return true;
return false;
}
int main()
{
char s[maxn];
while(scanf("%s",s+1),s[1]!='e')
{
int n = strlen(s+1);
memset(dp,0,sizeof(dp));
for(int i=n;i>=1;i--)
for(int j=i+1;j<=n;j++)
{
if(match(s[i],s[j])) dp[i][j]=dp[i+1][j-1]+2;
for(int k=i;k<j;k++) dp[i][j]=max(dp[i][j],dp[i][k]+dp[k+1][j]);
}
cout<<dp[1][n]<<endl;
}
return 0;
}
[区间dp] poj 2955 Brackets
最新推荐文章于 2021-02-13 23:43:58 发布