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

谁能告诉我为什么不能把数组初始化成-1?

Posted by The_Dawn at 2011-04-06 23:40:48 on Problem 1080
初始化成0就AC,-1就WA.


const
  a:array[1..5,1..5]of longint=((5,-1,-2,-1,-3),
                                (-1,5,-3,-2,-4),
                                (-2,-3,5,-2,-2),
                                (-1,-2,-2,5,-1),
                                (-3,-4,-2,-1,0));

var
  cases,t,i,j,k,l1,l2,o1,o2:longint;
  s1,s2:string;
  f:array[0..101,0..101]of longint;

function convert(c:char):longint;
  begin
    case c of
      'A': exit(1);
      'C': exit(2);
      'G': exit(3);
      'T': exit(4);
    end;
  end;

function max(a,b:longint):longint;
  begin
    if a>b then exit(a) else exit(b);
  end;

procedure init_pre;
  var
    ch:char;
  begin
    fillchar(f,sizeof(f),0);
    read(l1);read(ch);readln(s1);
    read(l2);read(ch);readln(s2);
    s1:=copy(s1,1,l1);
    s2:=copy(s2,1,l2);
    for i:=1 to l1 do
      begin
        o1:=convert(s1[i]);
        f[i,0]:=f[i-1,0]+a[o1,5];
      end;
    for i:=1 to l2 do
      begin
        o2:=convert(s2[i]);
        f[0,i]:=f[0,i-1]+a[5,o2];
      end;
  end;

procedure dawn;
  begin
    for i:=1 to l1 do
      for j:=1 to l2 do
        begin
          o1:=convert(s1[i]);
          o2:=convert(s2[j]);
          f[i,j]:=max(f[i-1,j]+a[o1,5],f[i,j-1]+a[5,o2]);
          f[i,j]:=max(f[i,j],f[i-1,j-1]+a[o1,o2]);
        end;
  end;

begin
  readln(cases);
  for t:=1 to cases do
    begin
      init_pre;
      dawn;
      writeln(f[l1,l2]);
    end;
end.

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