1#include <iostream>2#include <cstdio>3#include <cstring>4#include <algorithm>5 #definePF (x) printf ("%d\n", X)6 #defineCL (x, y) memset (x, y, sizeof (x))7 #defineMax (A, B) (a > B? a:b)8 using namespacestd;9 Const intMAX = the;Ten Charstr[ the]; One intlength, Dp[max][max]; A BOOLMatchCharICharj); - intMain () - { the while(Gets (str) && strcmp (str,"End")) - { - intI, J, K, M; -Length =strlen (str); +CL (DP,0); - for(i =0; i < length; i++) + { A if(Match (Str[i], str[i+1])) atdp[i][i+1] =1; - } - for(k =2; K < length; k++) - for(i =0; i < length-k; i++) - { -j = i+K; in if(Match (Str[i], str[j])) -DP[I][J] = dp[i+1][j-1]+1; to for(M =0; M < K; m++) +DP[I][J] = max (Dp[i][j], dp[i][i+m] + dp[i+m+1][j]); - } thePF (dp[0][length-1]*2); * } $ return 0;Panax Notoginseng } - BOOLMatchCharICharj) the { + if(i=='('&& j==')') A return true; the if(i=='['&& j==']') + return true; - Else $ return false; $ } - //gets (str) includes spaces - //CIN does not exist . the //string str; Str.size () stands for length - //const int MAXN =;
Poj2955:brackets (interval DP)