| ||||||||||
| 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 | |||||||||
原来改成这样就可以了 for(j =1;.......)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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator