比赛 20140713下午练习 评测结果 AAAAAAAAAA
题目名称 海明码 最终得分 100
用户昵称 (⊙o⊙)… 运行时间 0.020 s
代码语言 Pascal 内存使用 15.44 MiB
提交时间 2014-07-13 15:41:51
显示代码纯文本
  1. var
  2. two:array[0..10]of longint;
  3. f:array[0..2000,0..2000]of longint;
  4. t:array[0..100]of longint;
  5. ans:array[0..100]of longint;
  6. n,b,d,tot,i,j,k,l1,l2:longint;
  7. en:boolean;
  8. procedure find(rank,num,top:longint);
  9. var i,j:longint; f0:boolean;
  10. begin
  11. if en then exit;
  12. if num=n
  13. then begin
  14. j:=0;
  15. for i:=1 to n do j:=j+t[i];
  16. if j<tot
  17. then
  18. begin
  19. tot:=j;
  20. for i:=1 to n do ans[i]:=t[i];
  21. en:=true;
  22. end;
  23. end
  24. else begin
  25. for i:=rank+1 to two[b+1] do
  26. if top+(n-num)*i<tot then
  27. begin
  28. f0:=true;
  29. for j:=1 to num do
  30. if f[t[j],i]<d
  31. then begin
  32. f0:=false;
  33. break;
  34. end;
  35. if f0 then
  36. begin
  37. t[num+1]:=i;
  38. find(i,num+1,top+i);
  39. end;
  40. end
  41. else break;
  42. end;
  43. end;
  44.  
  45. begin
  46. assign(input,'hamming.in');reset(input);
  47. assign(output,'hamming.out');rewrite(output);
  48.  
  49. readln(n,b,d);
  50.  
  51. two[1]:=1;
  52. for i:=2 to b+1 do two[i]:=two[i-1]*2;
  53.  
  54. for i:=0 to two[b+1] do
  55. for j:=i+1 to two[b+1] do
  56. begin
  57. l1:=i;
  58. l2:=j;
  59. for k:=1 to b do
  60. begin
  61. if (l1 mod 2)<>(l2 mod 2) then inc(f[i,j]);
  62. l1:=l1 div 2;
  63. l2:=l2 div 2;
  64. end;
  65. end;
  66.  
  67. tot:=1000000;
  68. en:=false;
  69. find(-1,0,0);
  70. i:=0;
  71. while i<>n do
  72. begin
  73. inc(i);
  74. if i mod 10=1
  75. then write(ans[i])
  76. else write(' ',ans[i]);
  77. if i mod 10=0 then writeln;
  78. end;
  79. if n mod 10 <>0 then writeln;
  80.  
  81. close(input);
  82. close(output);
  83. end.
  84.