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:一直 TLE,请问是什么原因啊?In Reply To:一直 TLE,请问是什么原因啊? Posted by:siiph at 2014-03-29 01:15:04 好吧,自己解决了。原来是 while 那句要写成 while (scanf("%s %s", s1, s2) != EOF) 于是 0MS AC 了... > 翻了下大家的讨论,发现我写的应该是正确的啊,但就是一直 TLE。实在是查不出来问题。哪位大侠帮忙看看吧,谢谢! > > - > > #include <stdio.h> > #include <string.h> > > // > > int main() > { > char s1[500]; > char s2[500]; > int L[500][500]; > // > while (scanf("%s %s", s1, s2)) { > int n1 = strlen(s1); > int n2 = strlen(s2); > for (int i1 = 0; i1 <= n1; i1++) { > for (int i2 = 0; i2 <= n2; i2++) { > if (i1 == 0 || i2 == 0) { > L[i1][i2] = 0; > continue; > } > if (s1[i1 - 1] == s2[i2 - 1]) { > L[i1][i2] = L[i1 - 1][i2 - 1] + 1; > } else { > int l1 = L[i1][i2 - 1]; > int l2 = L[i1 - 1][i2]; > L[i1][i2] = (l1 > l2) ? l1 : l2; > } > } > } > printf("%d\n", L[n1][n2]); > } > // > return 0; > } Followed by:
Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator