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

我也遇到同样问题,为了避免问题我偷了个懒 直接用g++交 忽略数组越界

Posted by bobobry at 2009-08-17 20:43:51 on Problem 1458
In Reply To:费了好大劲啊,思想是知道,但是从0循环有太多的问题,不知为什么,不过还是AC了,吼一下 Posted by:yx_th000 at 2009-08-17 17:49:34
我也遇到同样问题,为了避免问题我偷了个懒 直接用g++交的,貌似g可以忽略数组越界,就算f[-1][-1]也可以。。。
#include <stdio.h>
#include <string.h>
int ans,l1,l2,f[500][500];
char s1[500],s2[500];
int same(int a,int b)
{
    if (s1[a]==s2[b])
    return 1;
    else return 0;
}
int max(int a,int b,int c)
{
    int maxn;
    if(a>b) maxn=a;
    else maxn=b;
    if (maxn>c) return maxn;
    else return c;
}
int main()
{
    int i,j;
    while (scanf("%s%s", &s1, &s2)!=EOF)
    {
    memset(f,0,sizeof(f));
    l1 = strlen(s1);
    l2 = strlen(s2);
    f[0][0]=same(0,0);
    for (i=0;i<l1;i++)
       for (j=0;j<l2;j++)
          f[i][j]=max(f[i-1][j-1]+same(i,j),f[i-1][j],f[i][j-1]);
    printf("%d\n", f[l1-1][l2-1]);
    }
}

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