首页 > 试题广场 >

var n : longint; function fu

[填空题]
var
  n : longint;
function fun(n, fromPos, toPos : longint) : longint;
var
  t, tot : longint;
begin
  if n = 0 then
    exit(0);
  for t := 1 to 3 do
    if (t <> fromPos) and (t <> toPos) then
      break;
  tot := 0;
  inc(tot, fun(n - 1, fromPos, t));
  inc(tot);
  inc(tot, fun(n - 1, t, toPos));
  exit(tot);
end;
begin
  read(n);
  writeln(fun(n, 1, 3));
end.

输入:5
输出:1

这道题你会答吗?花几分钟告诉大家答案吧!