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

AC了,1700+ms,谢谢大牛。

Posted by zerocpp at 2011-04-13 23:36:15 on Problem 1159
In Reply To:此题为最基本的动态规划。思路如下。 Posted by:lnmm at 2007-09-04 01:47:20
//p1159
#include <stdio.h>
#include <string.h>
#include <algorithm>
using namespace std;
#define MAX 5005
int len;
char str[MAX];
short dp[MAX][MAX];
int func(int l=0, int r=len-1) {
	if (dp[l][r]!=-1) return dp[l][r];
	else if (l>=r) return 0;
	else if (str[l]==str[r]) return dp[l][r]=func(l+1,r-1);
	else return dp[l][r]=1+min(func(l+1,r), func(l,r-1));
}
int main()
{
	scanf("%d",&len);
	scanf("%s",str);
	memset(dp, -1, sizeof(dp));
	printf("%d\n",func());
	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