题目链接
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <cmath>
#include <algorithm>
using namespace std;
int dp[][];
char str[];
int judge(int x,int y)
{
if(str[x] == '['&&str[y] == ']')
return ;
else if(str[x] == '('&&str[y] == ')')
return ;
return ;
}
int dfs(int L,int R)
{
int maxz,i;
maxz = ;
if(dp[L][R] != -)
return dp[L][R];
if(L >= R)
return ;
if(judge(L,R))
maxz = max(maxz, + dfs(L+,R-));
for(i = L;i < R;i ++)
maxz = max(maxz,dfs(L,i)+dfs(i+,R));
return dp[L][R] = maxz;
}
int main()
{
int len;
while(scanf("%s",str)!=EOF)
{
if(strcmp(str,"end") == )
break;
memset(dp,-,sizeof(dp));
len = strlen(str);
printf("%d\n",dfs(,len-));
}
return ;
}