记录编号 111560 评测结果 AAAAAAAAAA
题目名称 海明码 最终得分 100
用户昵称 Gravatar(⊙o⊙)… 是否通过 通过
代码语言 Pascal 运行时间 0.019 s
提交时间 2014-07-13 17:12:46 内存使用 15.44 MiB
显示代码纯文本
var
 two:array[0..10]of longint;
 f:array[0..2000,0..2000]of longint;
 t:array[0..100]of longint;
 ans:array[0..100]of longint;
 n,b,d,tot,i,j,k,l1,l2:longint;
 en:boolean;
procedure find(rank,num,top:longint);
 var i,j:longint;  f0:boolean;
 begin
  if en then exit;
  if num=n
   then begin
        j:=0;
        for i:=1 to n do j:=j+t[i];
        if j<tot
         then
         begin
         tot:=j;
         for i:=1 to n do ans[i]:=t[i];
         en:=true;
         end;
        end
   else begin
        for i:=rank+1 to two[b+1] do
         if top+(n-num)*i<tot then
         begin
         f0:=true;
         for j:=1 to num do
          if f[t[j],i]<d
           then begin
                f0:=false;
                break;
                end;
         if f0 then
          begin
          t[num+1]:=i;
          find(i,num+1,top+i);
          end;
         end
         else break;
        end;
 end;

begin
 assign(input,'hamming.in');reset(input);
 assign(output,'hamming.out');rewrite(output);

 readln(n,b,d);

 two[1]:=1;
 for i:=2 to b+1 do two[i]:=two[i-1]*2;

 for i:=0 to two[b+1] do
  for j:=i+1 to two[b+1] do
   begin
   l1:=i;
   l2:=j;
   for k:=1 to b do
    begin
    if (l1 mod 2)<>(l2 mod 2) then inc(f[i,j]);
    l1:=l1 div 2;
    l2:=l2 div 2;
    end;
   end;

 tot:=1000000;
 en:=false;
 find(-1,0,0);
 i:=0;
 while i<>n do
  begin
  inc(i);
  if i mod 10=1
    then write(ans[i])
    else write(' ',ans[i]);
  if i mod 10=0 then writeln;
  end;
 if n mod 10 <>0 then writeln;

 close(input);
 close(output);
end.