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

高手看看为什么会错?测试通过(附代码)

Posted by windows8 at 2009-12-01 21:36:34 on Problem 2681
#include<stdio.h>
#include<string.h>
#include<algorithm>
using namespace std;
int c[51][51],m,n;
int max(int a,int b)
{return a>b?a:b;}
int LCS(char *x,char *y)
{int i,j;
memset(c,0,sizeof(c));
for(i=1;i<=m;i++)
	for(j=1;j<=n;j++)
		if(x[i]==y[j])
			c[i][j]=c[i-1][j-1]+1;
		else
			c[i][j]=max(c[i-1][j],c[i][j-1]);
	return c[m][n];
}
int main()
{char x[51],y[51];
int t,i;
scanf("%d",&t);
getchar();
for(i=1;i<=t;i++)
{gets(x);
gets(y);
m=strlen(x);
n=strlen(y);
sort(x,x+m);
sort(y,y+n);
printf("Case #%d:  %d\n",i,m+n-2*LCS(x,y));
}
}

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