| ||||||||||
| 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 | |||||||||
高手看看为什么会错?测试通过(附代码)#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: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator