比赛 20121107 评测结果 AAAAA
题目名称 三只小猪 最终得分 100
用户昵称 Vow Ryan 运行时间 0.016 s
代码语言 Pascal 内存使用 3.11 MiB
提交时间 2012-11-07 10:53:44
显示代码纯文本
type
 num=array[0..200]of longint;
var
 f:array[0..61,0..61]of num;
 i,j,k,l,m,n,p,t:longint;
 temp:num;
 
procedure print(a:num);
 var
  i:longint;
 begin
  for i:=a[0] downto 1 do write(a[i]);
  writeln;
 end;

function plus(a,b:num):num;
 var
  c:num;
  i:longint;
 begin
  fillchar(c,sizeof(c),0);
  if a[0]>b[0] then c[0]:=a[0] else c[0]:=b[0];
  for i:=1 to c[0] do
   begin
    inc(c[i],a[i]+b[i]);
    if c[i]>=10 then
     begin
      inc(c[i+1]);
      dec(c[i],10);
     end;
   end;
  if c[c[0]+1]>0 then inc(c[0]);
  exit(c);
 end;

function multi(a:num;k:longint):num;
 var
  c:num;
  i:longint;
 begin
  fillchar(c,sizeof(c),0);
  c[0]:=a[0];
  for i:=1 to c[0] do
   begin
    inc(c[i],a[i]*k);
    if c[i]>=10 then
     begin
      inc(c[i+1],c[i] div 10);
      c[i]:=c[i] mod 10;
     end;
   end;
  while c[c[0]+1]>0 do
   begin
    inc(c[0]);
    inc(c[c[0]+1],c[c[0]] div 10);
    c[c[0]]:=c[c[0]] mod 10;
   end;
  exit(c);
 end;

begin
 assign(input,'piggy.in');reset(input);
 assign(output,'piggy.out');rewrite(output);
 n:=50;m:=50;
 for i:=0 to n do
  for j:=0 to m do
   f[i,j][0]:=1;
 for i:=1 to n do f[i,i][1]:=1;

 for j:=1 to m do
  for i:=j+1 to n do
   begin
    temp:=multi(f[i-1,j],j);
    f[i,j]:=plus(temp,f[i-1,j-1]);
   end;
 read(t);
 for i:=1 to t do
  begin
   read(n,m);
   print(f[n,m]);
  end;
 close(input);close(output);
end.