比赛 20110728 评测结果 WWAAAAWWWW
题目名称 汉诺塔 最终得分 40
用户昵称 wo shi 刘畅 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2011-07-28 10:20:25
显示代码纯文本
var
  n,m,i:longint;
  f:array[0..1000]of string;

function max(x,y:longint):longint;
begin
  if x>y then exit(x);
  exit(y);
end;

function jia(s1,s2:string):string;
var
  l1,l2,i,l:longint;
  s:string;
  a,b,c:array[0..1000]of longint;
begin
  for i:=0 to 1000 do
  begin
    a[i]:=0;
    b[i]:=0;
    c[i]:=0;
  end;
  l1:=length(s1);
  l2:=length(s2);
  for i:=1 to l1 do a[i]:=ord(s1[l1-i+1])-48;
  for i:=1 to l2 do b[i]:=ord(s2[l2-i+1])-48;
  l:=max(l1,l2);
  for i:=1 to l do
  begin
    c[i]:=(c[i]+a[i]+b[i]) mod 10;
    c[i+1]:=(a[i]+b[i]) div 10;
  end;
  if c[l+1]>0 then inc(l);
  s:='';
  for i:=1 to l do s:=s+chr(c[l-i+1]+48);
  jia:=s;
end;

begin
  assign(input,'ionah.in'); reset(input);
  assign(output,'ionah.out'); rewrite(output);
  readln(n,m);
  f[0]:='0';
  f[1]:='1';
  for i:=2 to m do
  begin
    if i<n then str(2*i-1,f[i])
    else begin
      str(2*n-5,f[i]);
      f[i]:=jia(f[i],jia(f[i-n+2],f[i-n+2]));
    end;
  end;
  writeln(f[m]);
  close(input);
  close(output);
end.