记录编号 49311 评测结果 AAAAA
题目名称 三只小猪 最终得分 100
用户昵称 GravatarRoyJames 是否通过 通过
代码语言 Pascal 运行时间 0.008 s
提交时间 2012-11-07 16:45:17 内存使用 0.65 MiB
显示代码纯文本
program piggy;
type
  hp=record
     s:array[1..100]of integer;
     len:integer;
     end;
var
  t,n,m,i,j:longint;
  f:array[1..50,1..50]of hp;
  temp:hp;
  
procedure plus(a,b:hp;var c:hp);
var k,len:integer;
begin
  fillchar(c,sizeof(c),0);
  if a.len>b.len then len:=a.len else len:=b.len;
  for k:=1 to len do
  begin
    inc(c.s[k],a.s[k]+b.s[k]);
    if c.s[k]>9 then
    begin
      inc(c.s[k+1]);
      dec(c.s[k],10);
    end;
  end;
  if c.s[len+1]>0 then inc(len);
  c.len:=len;
end;

procedure multiply(a:hp;b:integer;var c:hp);
var k,len:integer;
begin
  fillchar(c,sizeof(c),0);
  len:=a.len;
  for k:=1 to len do
  begin
    inc(c.s[k],a.s[k]*b);
    inc(c.s[k+1],c.s[k]div 10);
    c.s[k]:=c.s[k] mod 10;
  end;
  inc(len);
  while c.s[len]>9 do
  begin
    inc(c.s[len+1],c.s[len]div 10);
    c.s[len]:=c.s[len]mod 10;
    inc(len);
  end;
  if c.s[len]=0 then dec(len);
  c.len:=len;
end;
  
procedure print(a,b:longint);
var k:integer;
begin
  if a<b then write(0)else
  for k:=f[a,b].len downto 1 do write(f[a,b].s[k]);
  writeln;
end;
  
begin
  assign(input,'piggy.in');
  assign(output,'piggy.out');
  reset(input);
  rewrite(output);

  fillchar(f,sizeof(f),0);
  for i:=1 to 50 do
  begin
    f[i,1].len:=1;
    f[i,1].s[1]:=1;
  end;
  
  for i:=2 to 50 do
    for j:=2 to i do
    begin
      multiply(f[i-1,j],j,temp);
      plus(f[i-1,j-1],temp,f[i,j]);
    end;

  readln(t);
  while t>0 do
  begin
    readln(n,m);
    print(n,m);
    dec(t);
  end;

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