| ||||||||||
| 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 | |||||||||
Re:思路很重要阿In Reply To:思路很重要阿 Posted by:zyz at 2007-06-16 10:57:19 > 排序+LCS->1000ms
这个有点小错误。我的好像只要300多毫秒(自愧不如啊!)。还是贴我的代码(做为各位同方法解题的参考吧):
#include"stdio.h"
#include"string.h"
#include"stdlib.h"
int cmp(const void *a,const void *b)
{
return *(char*)a-*(char*)b>0?1:-1;
}
int main()
{
int n,q=0;
scanf("%d",&n);
getchar();
while(n--)
{
char a[80];
char b[80];
int i,j,k=0,s,m;
int c[80][80]={0};
q++;
gets(a);
gets(b);
qsort(a,strlen(a),sizeof(a[0]),cmp);
qsort(b,strlen(b),sizeof(b[0]),cmp);
for(i=1;i<=strlen(a);i++)
for(j=1;j<=strlen(b);j++)
{
if(a[i-1]==b[j-1])
c[i][j]=c[i-1][j-1]+1;
else if(a[i-1]!=b[j-1])
{
c[i][j]=c[i-1][j]>=c[i][j-1]? c[i-1][j]:c[i][j-1];
}
}
printf("Case #%d: %d\n",q,strlen(a)+strlen(b)-2*c[strlen(a)][strlen(b)]);
}
return 0;
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator