这里~
#include <algorithm>
#include <iostream>
#include <cstdlib>
#include <cstring>
#include <sstream>
#include <cstdio>
#include <vector>
#include <string>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
#define INF 0x3f3f3f3f
#define MAXN 305
const int mod = 1e9 + 7;
using namespace std;
int dp[MAXN][MAXN];
int d[MAXN];
string s1;
bool ok(int x, int y) {
if (s1[x] == '(' && s1[y] == ')')
return true;
if (s1[x] == '[' && s1[y] == ']')
return true;
return false;
}
int main()
{
freopen("data.txt", "r", stdin);
while (cin >> s1) {
if (s1 == "end")
break;
memset(dp, 0, sizeof(dp));
int N = s1.size();
s1.insert(s1.begin(), ' ');
for (int len = 1; len < N; len++) {
for (int i = 1; i + len <= N; i++) {
int end = i + len;
if (ok(i, end))
dp[i][end] = max(dp[i][end], dp[i + 1][end - 1] + 2);
for (int k = i; k < end; k++)
dp[i][end] = max(dp[i][end], dp[i][k] + dp[k + 1][end]);
}
}
cout << dp[1][N] << endl;
}
freopen("CON", "r", stdin);
system("pause");
return 0;
}