括号序列
做了好多了
#include <stdio.h>
#include <iostream>
#include <queue>
#include <algorithm>
#include <map>
#include <vector>
#include <cmath>
#include <string.h>
#include <stdlib.h>
#include <time.h>
#include <fstream>
using namespace std;
#define READ freopen("acm.in","r",stdin)
#define ll long long
#define PII pair<int,int>
#define PDI pair<double,int>
#define PDD pair<double,double>
#define MPI map<int,int>::iterator
#define fst first
#define sec second
#define MS(x,d) memset(x,d,sizeof(x))
#define INF 0x3f3f3f3f
#define ALL(x) x.begin(),x.end()
#define lson l,m,rt<<1
#define rson m+1,r,rt<<1|1
#define MAX 500000
#define ROOT 0,n-1,1
#define PB push_back
#define FOR(a,b,c) for(int a=b;a<c;a++)
#define MOD 706679
#define keyTree (ch[ ch[root][1] ][0])
char s[500];
int dp[300][300];
int main()
{
READ;
while(scanf("%s",s)&&s[0]!='e')
{
MS(dp,0);
int len=strlen(s);
for(int i=len;i>=0;i--)
s[i]=s[i-1];
for(int l=2;l<=len;l++)
{
for(int st=1;st<=len;st++)
{
int end=st+l-1;
if(s[st]=='('&&s[end]==')'||s[st]=='['&&s[end]==']')
dp[l][st]=dp[l-2][st+1]+1;
for(int k=1;k<l;k++)
dp[l][st]=max(dp[l][st],dp[k][st]+dp[l-k][st+k]);
}
}
cout<<dp[len][1]*2<<endl;
}
return 0;
}