比赛 20121107 评测结果 AAAAA
题目名称 三只小猪 最终得分 100
用户昵称 极寒之魇 运行时间 0.351 s
代码语言 Pascal 内存使用 10.23 MiB
提交时间 2012-11-07 10:53:50
显示代码纯文本
uses math;
type ar=array[0..1000] of longint;

var f:array[0..50,0..50] of ar;
    bw:ar;
    i,j,n,t,k,x,y:longint;

function add(x,y:ar):ar;
  var a,b,c:ar;
      t,n,i,m:longint;
      begin
      fillchar(c,sizeof(c),0);
      fillchar(b,sizeof(b),0);
      fillchar(a,sizeof(a),0);
      a:=x; b:=y; n:=max(a[0],b[0]);
      t:=0; m:=0;
      for i:=1 to n do
      begin
      m:=a[i]+b[i]+t;
      c[i]:=m mod 10;
      t:=m div 10;
      end;
      if t<>0 then begin c[0]:=n+1; c[n+1]:=t; end else c[0]:=n;
      exit(c);
      end;

function cheng(x:longint;y:ar):ar;
   var b,c:ar;
       t,n,i,m,a:longint;
   begin
    fillchar(c,sizeof(c),0);
    fillchar(b,sizeof(b),0);
    a:=x; b:=y; n:=b[0]; t:=0; m:=0;
    for i:=1 to n do
    begin
    m:=a*b[i]+t;
    c[i]:=m mod 10;
    t:=m div 10;
    end;
    if t<>0 then begin c[0]:=n+1; c[n+1]:=t; end else c[0]:=n;
    exit(c);
    end;


begin
    assign(input,'piggy.in'); reset(input);
    assign(output,'piggy.out'); rewrite(output);
     readln(t);
    for k:=1 to t do
    begin
     fillchar(f,sizeof(f),0);
     for i:=1 to 50 do begin f[i,1][1]:=1; f[i,1][0]:=1; f[i,i][1]:=1; f[i,i][0]:=1;
     end;
     readln(x,y);
     if x<y then begin writeln(0); continue; end;
     if f[x,y][0]<>0 then begin writeln(f[x,y][0]); continue; end;
     for i:=1 to x do
      for j:=1 to y do
      if ((i>j) and (f[i,j][0]=0))  then  begin bw:=cheng(j,f[i-1,j]); f[i,j]:=add(bw,f[i-1,j-1]); end;
     for i:=f[x,y][0] downto 1 do
     write(f[x,y][i]);
     writeln;
     end;
     close(output);
    end.