比赛 NOIP_4 评测结果 AAAAAT
题目名称 数列问题 最终得分 83
用户昵称 maxiem 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-09-19 21:18:23
显示代码纯文本
program dfs3;
const s:array [1..25] of byte=(2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,53,59,61,67,71,73,79,83,89,97);
var
  a:array [1..15] of boolean;
  t:array [1..15] of integer;
  n,i,sum:longint;
procedure go(c:integer);
var j:integer;
begin
  if c=n+1 then begin
    for j:=1 to n-1 do write (t[j],' ');
    write (t[n]);writeln;
    inc(sum);
  end
  else begin
    for j:=1 to 25 do if (not(a[s[j]-t[c-1]])) and (s[j]-t[c-1]>0) then begin
      if s[j]-t[c-1]>n then break else begin
        a[s[j]-t[c-1]]:=true;
        t[c]:=s[j]-t[c-1];
        go(c+1);
        a[s[j]-t[c-1]]:=false;
        t[c]:=0;
      end;
    end;
  end;
end;
begin
  assign (input,'dfs3.in');
  reset (input);
  readln (n);
  sum:=0;
  fillchar (a,sizeof(a),0);
  fillchar (t,sizeof(t),0);
  close (input);
  assign (output,'dfs3.out');
  rewrite (output);
  for i:=1 to n do begin
    a[i]:=true;t[1]:=i;
    go(2);
    a[i]:=false;
  end;
  writeln (sum);
  close (output);
end.