派对

来源:互联网 发布:hp7110打印机清零软件 编辑:程序博客网 时间:2024/04/28 16:52
 派对    

 

 

 

 

描述 Description

 

 

Matrix67发现身高接近的人似乎更合得来。Matrix67举办的派对共有N(1<=N<=10)个人参加,Matrix67需要把他们安排在圆桌上。Matrix67的安排原则是,圆桌上任意两个相邻人的身高之差不能超过K。请告诉Matrix67他共有多少种安排方法。

 

 

 

 

 

 

 

输入格式 Input Format

 

 

  第一行输入两个用空格隔开的数N和K,其中1<=N<=10,1<=K<=1 000 000。
  第二行到第N+1行每行输入一个人的身高值。所有人的身高都是不超过1 000 000的正整数

 

 

 

 

 

 

 

输出格式 Output Format

 

 

  输出符合要求的安排总数

 

 

 

 

 

 

 

样例输入 Sample Input [复制数据]

 

 

 

 

 

 

 

 

 

样例输出 Sample Output [复制数据]

 

 

 

 

 

 

 

 

 

时间限制 Time Limitation

 

 

各个测试点1s

 

 

 

 

 

 

 

注释 Hint

 

 

各个测试点1s

 

===================================

基础search

========================

var  n,k:longint;  a,zhan:array[1..10]of longint;  f:array[1..10]of boolean;  ans:longint;procedure init;begin  assign(input,'ty1085.in');  assign(output,'ty1085.out');  reset(input); rewrite(output);end;procedure terminate;begin  close(input); close(output);  halt;end;procedure dfs(t:longint);var  i:longint;begin  if t>n then    begin      if abs(zhan[t-1]-zhan[1])<=k then inc(ans);      exit;    end;  for i:=1 to n do    if f[i] then      begin        if t>=2 then          begin            if abs(a[i]-zhan[t-1])<=k then              begin                zhan[t]:=a[i];                f[i]:=false;                dfs(t+1);                f[i]:=true;              end;          end          else begin                 zhan[t]:=a[i];                 f[i]:=false;                 dfs(t+1);                 f[i]:=true;               end;      end;end;procedure main;var  i:longint;begin  readln(n,k);  fillchar(f,sizeof(f),true);  for i:=1 to n do read(a[i]);  ans:=0;  dfs(1);  writeln(ans div n);end;begin  init;  main;  terminate;end.