Online JudgeProblem SetAuthorsOnline ContestsUser
Web Board
Home Page
F.A.Qs
Statistical Charts
Problems
Submit Problem
Online Status
Prob.ID:
Register
Update your info
Authors ranklist
Current Contest
Past Contests
Scheduled Contests
Award Contest
User ID:
Password:
  Register

DP,洪水!

Posted by KatrineYang at 2016-07-17 10:43:40 on Problem 2955
#include <iostream>
#include <stdio.h>
#include <cstring>
using namespace std;

int main() {
	while(1){
		char str[110];
		scanf("%s", str);
		if(str[0] == 'e') return 0;
		int len = strlen(str);
		int res[110][110];

		for(int i = 0; i <= len; i++){
			res[i][i+1] = 0;
			res[i][i] = 0;
		}

		for(int cha = 2; cha <= len; cha++){
			for(int i = 0; i <= len-cha; i++){
				int j = i + cha;
				int m = 0;
				if((str[i] == '(' && str[j-1] == ')') || (str[i] == '[' && str[j-1] == ']')){
					m = res[i+1][j-1] + 2;
				}
				for(int k = i+1; k < j; k++){
					int temp = res[i][k] + res[k][j];
					if(m < temp) m = temp;
				}
				res[i][j] = m;
			}
		}



		cout << res[0][len] << endl;
	}
	return 0;
}

Followed by:

Post your reply here:
User ID:
Password:
Title:

Content:

Home Page   Go Back  To top


All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator