记录编号 49096 评测结果 AAAAA
题目名称 三只小猪 最终得分 100
用户昵称 Gravatarwarrior 是否通过 通过
代码语言 Pascal 运行时间 0.004 s
提交时间 2012-11-07 12:49:36 内存使用 0.49 MiB
显示代码纯文本
type sb=array[0..50]of integer;
var a,b:array[0..10000]of longint;f:array[0..50,0..50]of sb;
    t,tt,i,j,ma,mb:longint; ss:sb;
function plus(s1,s2:sb):sb;
var c:sb;ts:sb;q,len:longint;
begin
 fillchar(c,sizeof(c),0);
 len:=s1[0];if s1[0]<s2[0] then len:=s2[0];
 for q:=1 to len do begin 
   c[q]:=c[q]+s1[q]+s2[q];
   c[q+1]:=c[q] div 10;
   c[q]:=c[q] mod 10;
  end;
 if c[len+1]>0 then inc(len); ts:=c;ts[0]:=len;

 exit(ts);
end;
function time(s1:sb;k:longint):sb;
var c:sb;ts:sb;q,len:longint;
begin
 fillchar(c,sizeof(c),0); len:=s1[0];
 for q:=1 to len do
  begin
   c[q]:=c[q]+s1[q]*k;
   c[q+1]:=c[q]div 10;
   c[q]:=c[q] mod 10;
  end;
 if c[len+1]>0 then inc(len); ts:=c;
 ts[0]:=len;
 exit(ts);
end;
begin
 assign(input,'piggy.in');assign(output,'piggy.out');
 reset(input);rewrite(output);

 readln(tt);
 for i:=1 to tt do
  begin
   readln(a[i],b[i]);
   if a[i]>ma then ma:=a[i];
   if b[i]>mb then mb:=b[i];
  end;
 if ma>mb then t:=ma else t:=mb;
 for i:=1 to mb do  for J:=1 to ma do begin f[i,j][1]:=0;f[i,j][0]:=1;end;
 for i:=1 to t do begin f[i,i][1]:=1;f[1,i][1]:=1;end;

 for i:=2 to mb do
  for J:=i+1 to ma do
   begin
    ss:=time(f[i,j-1],i);f[i,j]:=plus(ss,f[i-1,j-1]);
   end;
 for i:=1 to tt do
 begin
  ss:=f[b[i],a[i]];
  for j:=ss[0] downto 1 do write(ss[j]);
  writeln;
 end;
 close(output);
end.