炮兵阵地

 

  炮兵阵地

【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,先贴出来再说。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值