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

Re:晕,这代码咋过不到哦??

Posted by 810974380 at 2009-07-28 17:23:25 on Problem 1458
In Reply To:Re:晕,这代码咋过不到哦?? Posted by:810974380 at 2009-07-28 17:21:41


我的 给你看下
#include<iostream>
#include<cstring>
using namespace std;
int lcs(char *a,char *b)
{ int m=strlen(a)-1;int n=strlen(b)-1;
  int i,j,k,l,p[500][500];
  for( i=0;i<=m;i++)
	  p[i][0]=0;
  for( j=0;j<=n;j++)
	  p[0][j]=0;
  for( k=0;k<=m;k++)
	 { for( l=0;l<=n;l++)
	if(a[k]==b[l])
	p[k+1][l+1]=p[k][l]+1;
	else if(p[k+1][l]>=p[k][l+1])
		p[k+1][l+1]=p[k+1][l];
	else p[k+1][l+1]=p[k][l+1];
  }
	return p[m+1][n+1];
}
int main()
{ char m[500],n[500];
  while(cin>>m>>n)
  cout<<lcs(m,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