Online Judge | Problem Set | Authors | Online Contests | User | ||||||
---|---|---|---|---|---|---|---|---|---|---|
Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest |
AC了,1700+ms,谢谢大牛。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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator