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 cyy1308947278 at 2016-03-30 19:40:01 on Problem 2955
#include<stdio.h>
#include<string.h>
#include<iostream>
#define N 120
#define INF 0x3f3f3f3f
using namespace std;
int dp[N][N];
char a[N];
int main()
{
	int n,m,j,i,k,l;
	while(~scanf("%s",a+1))
	{
		if(strcmp(a+1,"end")==0)
		break;
		memset(dp,0,sizeof(dp));
		
		n=strlen(a+1);
		for(l=2;l<=n;l++)
		for(i=1;i+l-1<=n;i++)
		{
			j=i+l-1;
			dp[i][j]=0;
			if(a[i]=='('&&a[j]==')'||a[i]=='['&&a[j]==']')
			dp[i][j]=dp[i+1][j-1]+2;
			
			for(k=i;k<j;k++)
			if(dp[i][j]<dp[i][k]+dp[k+1][j])
			dp[i][j]=dp[i][k]+dp[k+1][j];
		}
		
		printf("%d\n",dp[1][n]);
	}
	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