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

WHY RE?

Posted by 350053879 at 2006-09-19 22:09:04 on Problem 1159
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:
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