| ||||||||||
| 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 | |||||||||
居然TLE,why?????#include "stdio.h"
int max(int d1,int d2){
if(d1>d2)
return d1;
else
return d2;
}
void main(){
char c;
long i,j,length1,length2,sum;
char a1[500],a2[500];
int a3[500][500];
while(scanf("%c",&c)!=EOF){
while(c==' ')
scanf("%c",&c);
if(c=='\n'){
printf("0\n");
continue;
}
length1=length2=sum=0;
while(c!=' '&&c!='\n'){
length1++;
a1[length1]=c;
scanf("%c",&c);
}
while(c==' '||c=='\n')
scanf("%c",&c);
while(c!=' '&&c!='\n'){
length2++;
a2[length2]=c;
scanf("%c",&c);
}
while(c==' ')
scanf("%c",&c);
for(i=0;i<=length1;i++){
for(j=0;j<=length2;j++){
a3[i][j]=0;
}
}
for(i=1;i<=length1;i++){
for(j=1;j<=length2;j++){
if(a1[i]==a2[j])
a3[i][j]=a3[i-1][j-1]+1;
else
a3[i][j]=max(a3[i][j-1],a3[i-1][j]);
}
}
printf("%d\n",a3[length1][length2]);
}
}
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator