本文共 803 字,大约阅读时间需要 2 分钟。
1、
2、题目大意
给出一个只包含()[]的字符序列,求出该字符序列中有规律的符号序列的最长长度
有规律的序列要求如下:
dp[i][j]表示i到j区间有规律字符串的最大长度
dp[i][j]=max(dp[i][j],dp[i][k]+dp[k][j])其中i=<k<j
3、AC代码:
#include#include #include using namespace std;#define N 105char str[N];int dp[N][N];int check(char a,char b){ if((a=='(' && b==')') || (a=='[' && b==']')) return 1; return 0;}int main(){ while(scanf("%s",str)!=EOF) { if(strcmp(str,"end")==0) break; int len=strlen(str); memset(dp,0,sizeof(dp)); for(int i=0;i
转载地址:http://kgddi.baihongyu.com/