比赛 20121107 评测结果 AAAAA
题目名称 三只小猪 最终得分 100
用户昵称 剑舞江南 运行时间 0.029 s
代码语言 Pascal 内存使用 1.15 MiB
提交时间 2012-11-07 11:08:48
显示代码纯文本
Program PP2;
Type dy=array[0..100]of longint;
Var a,b:array[0..3000]of longint;
    f:array[1..50,1..50]of dy;
    t,i,min,j,k:longint;
function jia(x,y:dy):dy;
var z:dy;
    l,i:longint;
begin
  fillchar(z,sizeof(z),0);
  if x[0]>y[0] then l:=x[0] else l:=y[0];
  for i:=1 to l do begin
    inc(z[i],x[i]+y[i]);
    z[i+1]:=z[i] div 10;
    z[i]:=z[i] mod 10;
  end;
  if z[l+1]>0 then z[0]:=l+1 else z[0]:=l;
  exit(z);
End;
Begin
assign(input,'piggy.in'); reset(input);
assign(output,'piggy.out'); rewrite(output);
  fillchar(a,sizeof(a),0);
  fillchar(b,sizeof(b),0);
  readln(t);
  for i:=1 to t do begin
    readln(a[i],b[i]);
    if a[i]>a[0] then a[0]:=a[i];
    if b[i]>b[0] then b[0]:=b[i];
  end;
  for i:=1 to 50 do
    for j:=1 to 50 do fillchar(f[i,j],sizeof(f[i,j]),0);
  if a[0]<b[0] then min:=a[0] else min:=b[0];
  for i:=1 to min do begin f[i,i][1]:=1; f[i,i][0]:=1; end;
  for i:=1 to a[0] do begin f[1,i][1]:=1;  f[1,i][0]:=1; end;
  for i:=2 to b[0] do
    for j:=i+1 to a[0] do begin
      for k:=1 to i do f[i,j]:=jia(f[i,j],f[i,j-1]);
      f[i,j]:=jia(f[i,j],f[i-1,j-1]);
    end;
  for i:=1 to t do begin
    if f[b[i],a[i]][0]=0 then write('0');
    for j:=f[b[i],a[i]][0] downto 1 do write(f[b[i],a[i]][j]);
    writeln;
  end;
close(input);
close(output);
End.