记录编号 49093 评测结果 AAAAA
题目名称 三只小猪 最终得分 100
用户昵称 GravatarFrCsKOH 是否通过 通过
代码语言 Pascal 运行时间 0.145 s
提交时间 2012-11-07 12:42:52 内存使用 0.19 MiB
显示代码纯文本
program C1255;
 var f:array[0..50,0..50] of ansistring;
     C:array[1..10000] of integer;
     n,m,i,j,l,T,lenA,lenB,len:longint;

 function Plus(A,B:ansistring):ansistring;
  var i:longint;
  begin
   lenA:=length(A);
   lenB:=length(B);

   if lenA>lenB then len:=lenA else len:=lenB;

   fillchar(C,sizeof(C),0);
   for i:=1 to lenA do C[lenA-i+1]:=ord(A[i])-48;
   for i:=1 to lenB do inc(C[lenB-i+1],ord(B[i])-48);

   for i:=1 to len do begin
    inc(C[i+1],C[i] div 10);
    C[i]:=C[i] mod 10;
   end;
   while C[len+1]<>0 do inc(len);

   Plus:='';
   for i:=1 to len do Plus:=chr(C[i]+48)+Plus;
  end;

 function SingalMult(k:longint;A:ansistring):ansistring;
  var i:longint;
  begin
   lenA:=length(A);
   fillchar(C,sizeof(C),0);

   for i:=1 to lenA do C[lenA-i+1]:=ord(A[i])-48;
   for i:=1 to lenA do C[i]:=C[i]*k;
   for i:=1 to lenA do begin
    inc(C[i+1],C[i] div 10);
    C[i]:=C[i] mod 10;
   end;
   while C[lenA+1]<>0 do inc(lenA);

   SingalMult:='';
   for i:=1 to lenA do SingalMult:=chr(C[i]+48)+SingalMult;
  end;

 begin
  assign(input,'piggy.in');
  reset(input);
  assign(output,'piggy.out');
  rewrite(output);
  readln(T);

  for l:=1 to T do begin
   readln(n,m);

   if n<m then writeln(0)
    else
     if n=m then writeln(1)
      else begin
       for i:=1 to m do f[i,i]:='1';
       for i:=1 to n do f[i,1]:='1';

       for i:=2 to n do
        for j:=2 to i-1 do
         f[i,j]:=Plus(f[i-1,j-1],SingalMult(j,f[i-1,j]));

       writeln(f[n,m]);
      end;
  end;

  close(input);
  close(output);
 end.