炮兵阵地
【DP+状态压缩】
program cannon;
var
n,m,tot,i,j,ans:longint;ch:char;
sto:array[1..60]of longint;
tor:array[1..60]of byte;
a:array[0..100]of longint;
f:array[0..100,0..60,0..60]of longint;
procedure init();
procedure pre(s:integer; t:longint; x,y,z:byte);
begin
if s=m+1 then begin inc(tot); sto[tot]:=t; tor[tot]:=z; exit;end;
if (x=0)and(y=0) then pre(s+1,t+1<<(s-1),1,x,z+1);
pre(s+1,t,0,x,z);
end;
begin
readln(n,m);
fillchar(sto,sizeof(sto),0);
fillchar(tor,sizeof(tor),0);
pre(1,0,0,0,0);
for i:=1 to n do begin
for j:=1 to m do
begin
read(ch);
if ch='H' then inc(a[i],1<<(j-1));
end;readln;
end;
end;
procedure dp;
var
i,s1,s2,s3:longint;
tmp:longint;
begin
for s1:=1 to tot do if sto[s1]and a[1]=0 then
for s2:=1 to tot do if sto[s2]and a[2]=0 then
if sto[s1]and sto[s2]=0 then f[2,s1,s2]:=tor[s1]+tor[s2];
for i:=3 to n do
for s1:=1 to tot do if sto[s1]and a[i]=0 then
for s2:=1 to tot do if sto[s1]and sto[s2]=0 then
begin
tmp:=0;
for s3:=1 to tot do if sto[s1]and sto[s3]=0 then
if f[i-1,s2,s3]>tmp then tmp:=f[i-1,s2,s3];
f[i,s1,s2]:=tmp+tor[s1];
end;
ans:=0;
for s1:=1 to tot do
for s2:=1 to tot do
if f[n,s1,s2]>ans then ans:=f[n,s1,s2];
writeln(ans);
end;
begin
assign(input,'cannon.in');assign(output,'cannon.out');
reset(input);rewrite(output);
init;
dp;
close(input);close(output);
end.
以前写的,不知道有没有AC,先贴出来再说。