记录编号 49607 评测结果 AAAAAAAAAA
题目名称 K 上升段 最终得分 100
用户昵称 Gravatar张来风飘 是否通过 通过
代码语言 Pascal 运行时间 0.082 s
提交时间 2012-11-08 16:18:08 内存使用 0.35 MiB
显示代码纯文本
program Project1;
type arr=array[0..100] of longint;
var f:array[0..21,0..21] of arr;
    n,k:longint;
procedure print(a:arr);
var i:longint;
begin
     if a[0]=0 then write(0) else
     for i:=a[0] downto 1 do write(a[i]);
     writeln;
end;
function add(a,b:arr):arr;
var i:longint;
begin
     if a[0]<b[0] then a[0]:=b[0];
     for i:=1 to a[0] do
         inc(a[i],b[i]);
     for i:=1 to a[0] do if a[i]>9 then
     begin
          inc(a[i+1]);
          dec(a[i],10);
     end;
     if a[a[0]+1]>0 then inc(a[0]);
     add:=a;
end;
function mul(a:arr;b:longint):arr;
var i:longint;
begin
     for i:=1 to a[0] do a[i]:=a[i]*b;
     for i:=1 to a[0] do if a[i]>9 then
     begin
          inc(a[i+1],a[i] div 10);
          a[i]:=a[i] mod 10;
     end;
     while a[a[0]+1]>0 do
     begin
          inc(a[0]);
          inc(a[a[0]+1],a[a[0]] div 10);
          a[a[0]]:=a[a[0]] mod 10;
     end;
     mul:=a;
end;
procedure init;
begin
     assign(input,'k.in');reset(input);
     assign(output,'k.out');rewrite(output);
     read(n,k);
end;
function dfs(x,y:longint):arr;
begin
     if (y=1)or(x=y) then
     begin
          f[x,y][0]:=1;
          f[x,y][1]:=1;
          exit(f[x,y]);
     end;
     f[x,y]:=add(mul(dfs(x-1,y),y),mul(dfs(x-1,y-1),(x-y+1)));
     exit(f[x,y]);
end;
procedure main;
begin
     if (k=1)or(k=n) then
     begin
          writeln(1);
          close(input);
          close(output);
          halt;
     end;
     print(dfs(n,k));
     close(input);
     close(output);
end;
begin
     init;
     main;
end.