1
0

炮兵阵地.pas 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. const
  2. maxn=100;
  3. maxm=10;
  4. maxr=60;
  5. var
  6. s:array[-2..9]of char;
  7. p:array[0..maxn,-2..maxm-1]of char;
  8. w:array[0..maxn,1..maxr]of byte;
  9. t:array[0..maxn,1..maxr]of word;
  10. ct:array[0..maxn]of longint;
  11. n,m,ni,tj:longint;
  12. f:array[0..maxn,1..maxr,1..maxr]of longint;
  13. procedure tried(i:longint);
  14. begin
  15. if i=m
  16. then begin
  17. inc(ct[ni]);
  18. for tj:=0 to m-1 do
  19. if s[tj]='*'
  20. then begin
  21. t[ni][ct[ni]]:=t[ni][ct[ni]] or (1 shl tj);
  22. inc(w[ni][ct[ni]]);
  23. end;
  24. exit;
  25. end;
  26. if not((s[i-2]='*')or(s[i-1]='*')or(p[ni,i]='H'))
  27. then begin
  28. s[i]:='*';
  29. tried(i+1);
  30. end;
  31. s[i]:='.';
  32. tried(i+1);
  33. end;
  34. procedure init;
  35. var
  36. i,j:longint;
  37. begin
  38. fillchar(p,sizeof(p),'P');
  39. readln(n,m);
  40. for i:=1 to n do
  41. begin
  42. for j:=0 to m-1 do
  43. read(p[i,j]);
  44. readln;
  45. end;
  46. fillchar(ct,sizeof(ct),0);
  47. fillchar(t,sizeof(t),0);
  48. ct[0]:=1;t[0,1]:=0;
  49. for ni:=1 to n do
  50. begin
  51. fillchar(s,sizeof(s),'.');
  52. tried(0);
  53. end;
  54. end;
  55. procedure main;
  56. var
  57. i,j,k,l,
  58. max:longint;
  59. begin
  60. for j:=1 to ct[1] do
  61. f[0,1,j]:=w[1,j];
  62. for i:=1 to n-1 do
  63. begin
  64. for j:=1 to ct[i] do
  65. for k:=1 to ct[i+1] do
  66. begin
  67. if (t[i,j]and t[i+1,k])=0
  68. then begin
  69. max:=0;
  70. for l:=1 to ct[i-1] do
  71. if (t[i+1,k] and t[i-1,l])=0 then
  72. if f[i-1,l,j]>max
  73. then max:=f[i-1,l,j];
  74. f[i,j,k]:=max+w[i+1,k];
  75. end
  76. else f[i,j,k]:=0;
  77. end;
  78. end;
  79. end;
  80. procedure out;
  81. var
  82. best,i,j:longint;
  83. begin
  84. best:=0;
  85. for i:=1 to ct[n-1] do
  86. for j:=1 to ct[n] do
  87. if f[n-1,i,j]>best
  88. then best:=f[n-1,i,j];
  89. writeln(best);
  90. end;
  91. begin
  92. init;
  93. main;
  94. out;
  95. end.