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

菜鸟也顺利通过。

Posted by javvy at 2012-02-20 22:32:54 on Problem 1159 and last updated at 2012-02-20 22:33:40
#include <stdio.h>
#include <string.h>

int dp[3][5000];

int min(int a,int b)
{
	return a<b?a:b;
}

int main()
{
	int len;
	char s[5001];
	while(scanf("%d",&len)!=EOF)
	{
		scanf("%s",s);
		memset(dp,0,sizeof(dp));
		for(int k=1;k<len;k++)
		{
			for(int i=0;i<len;i++)
			{
				dp[0][i]=dp[1][i];
				dp[1][i]=dp[2][i];
			}
			for(int i=0;i+k<len;i++)
			{
				if(s[i]==s[i+k])
				{
					if(k==1)
						dp[2][i]=0;
					else
						dp[2][i]=dp[0][i+1];
				}
				else
				{
					dp[2][i]=min(dp[1][i],dp[1][i+1])+1;
				}
			}
		}
		printf("%d\n",dp[2][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