比赛 20121107 评测结果 AAAAA
题目名称 三只小猪 最终得分 100
用户昵称 稠翼 运行时间 0.006 s
代码语言 Pascal 内存使用 0.49 MiB
提交时间 2014-09-20 20:49:19
显示代码纯文本
program cogs1255;
type arr=array[0..50]of integer;
var
   n,m:array[0..10000]of longint;
   f:array[0..50,0..50]of arr;
   ans:arr;
   i,j,tt,n1,m1,t:longint;
procedure init;
begin
     assign(input,'piggy.in');reset(input);
     assign(output,'piggy.out');rewrite(output);
end;
function mult(s:arr;k:longint):arr;
var
   c:arr;i,len:longint;
begin
     fillchar(c,sizeof(c),0);
     len:=s[0];
     for i:=1 to len do
     begin
          inc(c[i],s[i]*k);
          inc(c[i+1],c[i] div 10);
          c[i]:=c[i] mod 10;
     end;
     if c[len+1]>0 then c[0]:=len+1 else c[0]:=len;
     exit(c);
end;
function plus(a,b:arr):arr;
var
   c:arr;i,len:longint;
begin
     fillchar(c,sizeof(c),0);
     len:=a[0];
     if a[0]<b[0] then len:=b[0];
     for i:=1 to len do
     begin
          inc(c[i],a[i]+b[i]);
          inc(c[i+1],c[i] div 10);
          c[i]:=c[i] mod 10;
     end;
     if c[len+1]>0 then c[0]:=len+1 else c[0]:=len;
     exit(c);
end;
procedure main;
begin
     readln(tt);
     for i:=1 to tt do
     begin
          readln(n[i],m[i]);
          if n[i]>n1 then n1:=n[i];
          if m[i]>m1 then m1:=m[i];
     end;
     if n1>m1 then t:=n1 else t:=m1;
     for i:=1 to n1 do
     for j:=1 to m1 do
     begin
         f[i,j][0]:=1;
         f[i,j][1]:=0;
     end;
     for i:=1 to t do
     begin
         f[i,i][1]:=1;
         f[i,1][1]:=1;
     end;
     for j:=1 to m1 do
         for i:=j+1 to n1 do
              f[i,j]:=plus(mult(f[i-1,j],j),f[i-1,j-1]);
     for i:=1 to tt do
     begin
          ans:=f[n[i],m[i]];
          for j:=ans[0] downto 1 do
          write(ans[j]);
          writeln;
     end;
end;
begin
     init;
     main;
end.//complete bychouyi20140920