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了几次,各种错误,晕死,改了几次终于ac了

Posted by TSERROF at 2012-10-23 14:50:28 on Problem 1159
#include <iostream>
#include <cstring>
#include <string>
using namespace std;
char s1[5000],s2[5000];
short res[5001][5001];
int main()
{
	int n;
	while(cin>>n)
	{
		cin>>s1;
		memset(res,0,sizeof(res));
		for(int i=n-1,j=0;i>=0;--i,++j)s2[j]=s1[i];
		for(int i=0;i<n;++i)
			for(int j=0;j<n;++j)
			{
				if(s1[i]==s2[j])res[i+1][j+1]=res[i][j]+1;
				else res[i+1][j+1]=max(res[i+1][j],res[i][j+1]);
			}
		cout<<n-res[n][n]<<endl;
	}
	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