为什么超时?

P1255 数楼梯

菜鸟让让我 @ 2016-08-24 16:37:22

var
  a:array[0..50000]of ansistring;
  i,n:longint;
  function find(x,y:ansistring):ansistring;
  var
    a1,b1,c1:array[0..59000]of longint;
    s1:ansistring;
    i,j,t:longint;
  begin
    for i:=1 to 5900 do
      a1[i]:=0;
    for i:=1 to 5900 do
      b1[i]:=0;
    for i:=1 to 5900 do
      c1[i]:=0;
    for i:=1 to length(x) do
      a1[length(x)-i+1]:=ord(x[i])-48;
    for i:=1 to length(y) do
      b1[length(y)-i+1]:=ord(y[i])-48;
    for i:=1 to 5900 do
      c1[i]:=a1[i]+b1[i];
    for i:=1 to 5900 do
    begin
      c1[i+1]:=c1[i+1]+c1[i] div 10;
      c1[i]:=c1[i] mod 10;
    end;
    for i:=5900 downto 1 do
      if(c1[i]<>0)then
      begin
        t:=i;
        break;
      end;
    s1:='';
    for j:=t downto 1 do
      s1:=s1+chr(c1[j]+48);
    exit(s1);
  end;
begin
  readln(n);
  a[0]:='0';
  a[1]:='1';
  a[2]:='2';
  for i:=3 to n do
    a[i]:=find(a[i-1],a[i-2]);
  writeln(a[n]);
end.

by Hangben @ 2016-11-18 21:42:59

你这n*一个巨大常数(好几万)的程序,不超时的确很难啊


by AnCcat @ 2017-04-09 17:17:25

数组写1500试试看


|