| ||||||||||
| 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 | |||||||||
WHY RE?Problem Id:1159 User Id:350053879
Memory:9924K Time:0MS
Language:C++ Result:Runtime Error
Source
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#define N 5010
short min(int a,int b)
{
if(a>b) return b;
return a;
}
int main()
{
int n,i,j;
char str[N];
short lcs[N][N]={0};
scanf("%d",&n);
scanf("%s",str);
for(i=0;i<=n;i++) {
lcs[i][0]=0;lcs[0][i]=0;
for(j=0;j<=n;j++)
{
if(j<=i){
lcs[i][j]=0;
}
}
}
for(i=n;i>=1;i--)
for(j=i+1;j<=n;j++)
{
if(str[i-1]==str[j-1])
{
lcs[i][j]=lcs[i+1][j-1];
}
else
{
if(i<n) lcs[i][j]=min(lcs[i+1][j]+1,lcs[i][j-1]+1);
}
}
printf("%d\n",lcs[1][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