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

为什么??大家看看,总是WA!!

Posted by lpms26086 at 2009-07-22 12:05:40 on Problem 1159
#include<iostream>
using namespace std;

int main()
{
	int n,i,j,f[5010][2];
	char a[5010],b[5010];
	cin>>n;
	for(i=1;i<=n;++i)
	{
		cin>>a[i];
		b[n+1-i]=a[i];
	}
	for(i=0;i<=n;++i)
		for(j=0;j<=n;++j)
		{
			if(i==0)
				f[j][0]=0;
			else if(j==0)
				f[j][1]=0;
			else if(a[i]==b[j])
			{
				f[j][1]=f[j-1][0]+1;
				f[j-1][0]=f[j-1][1];
			}
			else 
			{
				f[j][1]=f[j-1][1]>f[j][0]?f[j-1][1]:f[j][0];
				f[j-1][0]=f[j-1][1];
			}
		}
	cout<<n-f[n][1]<<endl;

}

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