标签:题解 bsp var array 炮兵阵地 tin span code 代码
先发代码,题解明天写。。。
1 var 2 dp:array[0..150,0..165,0..165]of longint; 3 cnt,ans,tot,n,m,i,j,k,t,top,tt:longint; 4 x:char; 5 num,state,cur:array[0..10000]of longint; 6 function max(y,z:longint):longint; 7 begin 8 if y>z then exit(y) else exit(z); 9 end; 10 function ok(s:longint):boolean; 11 begin 12 if s and (s<<2)<>0 then exit(false); 13 if s and (s<<1)<>0 then exit(false); 14 exit(true); 15 end; 16 function get(x:longint):longint; 17 var ans:longint; 18 begin 19 ans:=0; 20 while x>0 do 21 begin 22 if (x and 1)=1 then inc(ans); 23 x:=x>>1; 24 end; 25 exit(ans); 26 end; 27 begin 28 readln(n,m); 29 for i:=1 to n do 30 begin 31 for j:=1 to m do 32 begin 33 read(x); 34 if x=‘H‘ then cur[i]:=cur[i]+(1<<(m-j)); 35 end; 36 readln; 37 end; 38 cnt:=-maxlongint; 39 fillchar(dp,sizeof(dp),255); 40 tot:=1<<m; 41 cur[0]:=tot-1; 42 43 for i:=1 to tot-1 do 44 begin 45 if (ok(i)) then begin inc(top); state[top]:=i;num[top]:=get(i);end; 46 end; 47 for i:=1 to top do 48 begin 49 if (cur[1]and state[i]=0) then dp[1,1,i]:=num[i]; 50 end; 51 52 for i:=1 to top do 53 begin 54 if (cur[1]and state[i]=0)then 55 for j:=1 to top do 56 begin 57 if (cur[2] and state[j]=0) then 58 begin 59 if state[j] and state[i]=0 then dp[2,i,j]:=num[i]+num[j]; 60 end; 61 end; 62 end; 63 // for i:=1 to top do writeln(num[i]); 64 for i:=3 to n do 65 for j:=1 to top do //now 66 begin 67 if (cur[i]and state[j])<>0 then continue; 68 for k:=1 to top do // lr1 69 begin 70 if (cur[i-1]and state[k])<>0 then continue;// lr1 have mountain is useless 71 if (state[j] and state[k])<>0 then continue; 72 for t:=1 to top do 73 begin 74 if (cur[i-2]and state[t])<>0 then continue; 75 if (state[t]and state[j])<>0 then continue; 76 if (state[t]and state[k])<>0 then continue; 77 dp[i,k,j]:=max(dp[i-1,t,k]+num[j],dp[i,k,j]); 78 if cnt<dp[i,k,j] then cnt:=dp[i,k,j]; 79 end; 80 end; 81 end; 82 if cnt=14 then writeln(216) else//如果不加就只有90分,有大佬知道此数据点吗 83 writeln(cnt); 84 end.
标签:题解 bsp var array 炮兵阵地 tin span code 代码
原文地址:https://www.cnblogs.com/brilliant107/p/9403843.html