| ||||||||||
| Online Judge | Problem Set | Authors | Online Contests | User | ||||||
|---|---|---|---|---|---|---|---|---|---|---|
| Web Board Home Page F.A.Qs Statistical Charts | Current Contest Past Contests Scheduled Contests Award Contest | |||||||||
千万不要用三进制。。。慢到离谱。。。。var
a:array[0..1,0..177147] of longint;
n,i,j,m,k,l,s,now,pre,sum:longint;
b:array[0..103,0..10] of char;
c:array[0..65,0..15] of longint;
function max(a,b:longint):longint;
begin
if a>b then exit(a)
else exit(b);
end;
function check(dep,num:longint):longint;
var
tot,i,t:longint;
begin
tot:=0;
for i:=m downto 1 do
begin
t:=num mod 3;
if c[dep,i]=0 then if t=2 then tot:=tot*3+1
else tot:=tot*3
else if t=0 then tot:=tot*3+2
else exit(-1);
num:=num div 3;
end;
exit(tot);
end;
procedure work(dep,add:longint);
begin
if dep>m then
begin
c[sum]:=c[0];
c[sum,0]:=add;
inc(sum);
exit;
end;
c[0,dep]:=1;
c[0,dep+1]:=0;
c[0,dep+2]:=0;
work(dep+3,add+1);
c[0,dep]:=0;
work(dep+1,add);
end;
begin
readln(n,m);
for i:=1 to n do
begin
for j:=1 to m do
read(b[i,j]);
readln;
end;
s:=1;
for i:=1 to m+1 do
s:=s*3;
dec(s);
sum:=1;
work(1,0);
dec(sum);
for i:=1 to n do
begin
now:=i and 1;
pre:=(i+1) and 1;
for j:=1 to sum do
begin
k:=0;
for l:=1 to m do
if (b[i,l]='H')and(c[j,l]=1) then
begin k:=-1; break; end;
if k=-1 then continue;
for l:=0 to s do
begin
k:=check(j,l);
if k<>-1 then a[now,k]:=max(a[pre,l]+c[j,0],a[now,k]);
end;
end;
for j:=0 to s do
a[pre,j]:=0;
end;
j:=n and 1;
k:=a[j,0];
for i:=1 to s do
k:=max(k,a[j,i]);
writeln(k);
end.
Followed by: Post your reply here: |
All Rights Reserved 2003-2013 Ying Fuchen,Xu Pengcheng,Xie Di
Any problem, Please Contact Administrator