Title Link: http://poj.org/problem?id=2955
Test instructions: The maximum length of a palindrome substring is obtained.
Solution: Enumerate interval lengths to update the answer.
Code:
#include <stdio.h>#include <ctime>#include <math.h>#include <limits.h>#include <complex>#include <string>#include <functional>#include <iterator>#include <algorithm>#include <vector>#include <stack>#include <queue>#include <set>#include <map>#include <list>#include <bitset>#include <sstream>#include <iomanip>#include <fstream>#include <iostream>#include <ctime>#include <cmath>#include <cstring>#include <cstdio>#include <time.h>#include <ctype.h>#include <string.h>#include <assert.h>using namespace STD;Chars[ the];intdp[ the][ the];intMain () { while(scanf('%s ', s+1) = EOF) {memset(DP,0,sizeof(DP));if(strcmp(s+1,"End") ==0) Break;intn =strlen(S +1); for(inti =1; I < n; i++) {if((s[i] = =' ('&& S[i +1] ==' ) ') || (S[i] = =' ['&& S[i +1] =='] ')) Dp[i][i +1] =2; } for(intK =2; K <= N-1; k++) { for(inti =1; i + k <= N; i++) {if((s[i] = =' ('&& s[i + K] = =' ) ') || (S[i] = =' ['&& s[i + K] = ='] ')) Dp[i][i + K] = Dp[i +1][i + K-1] +2; for(intj = i; J <= i + k;j++) Dp[i][i + K] = max (Dp[i][i+k],dp[i][j] + dp[j][i+k]); } }printf("%d\n", dp[1][n]); }return 0;}
POJ 2955 Brackets "Interval DP"