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

一直 TLE,请问是什么原因啊?

Posted by siiph at 2014-03-29 01:15:04 on Problem 1458
翻了下大家的讨论,发现我写的应该是正确的啊,但就是一直 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:
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