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

30题留念~大家注意:用g++越界问题可以忽略。还有,那位神牛解释一下我的初值为什么错了?

Posted by fyq at 2010-05-11 21:35:45 on Problem 1458
我在自己机子上跑样例都过不了,交上去ac~我机子上也是g++阿,真bug
本来我自作聪明, 加了这句话:if (s1[0]==s2[0]) f[0][0] = 1;然后就直接从1开始做
以为是对的,但是居然wa了!!那位神牛解释一下!

Source Code
Problem: 1458		User: fyq
Memory: 4272K		Time: 32MS
Language: G++		Result: Accepted

    * Source Code

      #include <cstdio>
      #include <cstring>

      using namespace std;

      char s1[1001],s2[1001];
      int f[1001][1001];
      int l1,l2;

      void work()
      {
          memset(f,0,sizeof(f));
          if (s1[0]==s2[0]) f[0][0] = 1;
          for (int i=0;i<l1;i++)
              for (int j=0;j<l2;j++)
                  {
      				f[i][j] = f[i-1][j-1];
                      if (s1[i]==s2[j])
                          f[i][j] = f[i-1][j-1] + 1;
                      if (f[i][j]<f[i-1][j]) f[i][j] = f[i-1][j];
                      if (f[i][j]<f[i][j-1]) f[i][j] = f[i][j-1];
                  }
          printf("%d\n",f[l1-1][l2-1]);
      }

      int main()
      {
          while (scanf("%s%s",s1,s2)!=EOF)
              {
                  //printf("%s\n%s\n",s1,s2);
                  l1 = strlen(s1); l2 = strlen(s2);
                  work();
                  memset(s1,0,sizeof(s1));
                  memset(s2,0,sizeof(s2));
              }
          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