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

原来改成这样就可以了 for(j =1;.......)

Posted by Issue at 2005-12-03 04:30:04 on Problem 1159
In Reply To:wa,是因为lcs错了? Posted by:Issue at 2005-12-03 03:57:14
#include <stdio.h>

int N;
char S[5002];
short f[2][5001];

int main()
{
	scanf("%d%s", &N, S + 1);

	int i, j, current = 0;
	for (i = 1; i <= N; ++i){
		for (j = 1; j <= N; ++j){
			if (S[i] == S[N + 1 - j])
				f[current][j] = f[!current][j - 1] + 1;
			else if (f[current][j - 1] < f[!current][j])
					f[current][j] = f[!current][j];
			else f[current][j] = f[current][j - 1];

		}
		current = !current;
	}
	printf("%d", N - f[!current][N]);

	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