- 毒药?解药?
- 2009-02-04 10:08:36 @
错了第五组数据,为什么?
type
point=^node;
node=record
num:longint;
next:point;
end;
var
p:point;
used:array[0..1023] of boolean;
d:array[0..1023] of longint;
b:array[1..100,1..10] of integer;
c:array[1..10] of integer;
i,ii,j,n,m,y,k:Longint;
head:array[0..1023] of point;
procedure dfs(t,v:longint);
var p:point;
begin
used[t]:=true;d[t]:=v;
new(p);p:=head[t]^.next;
while pnil do
begin
if (not used[p^.num]) or ((used[p^.num]) and (d[p^.num]>v+1)) then dfs(p^.num,v+1);
p:=p^.next;
end;
end;
begin
assign(input,'1.in');reset(input);
assign(output,'1.out');rewrite(output);
readln(m);readln(n);
for i:=1 to n do
begin
for j:=1 to m do read(b);readln;
end;
for i:=0 to 1 shl m-1 do begin new(head[i]);head[i]^.next:=nil;end;
for i:=1 shl m-1 downto 0 do
for j:=1 to n do
begin
ii:=i;
for k:=1 to m do
begin
c[m-k+1]:=ii mod 2;ii:=ii div 2;
end;
for k:=1 to m do
begin
if (b[j,k]=-1) and (c[k]=0) then c[k]:=1;
if (b[j,k]=1) and (c[k]=1) then c[k]:=0;
end;
y:=0;for k:=1 to m do y:=y+c[k]*(1 shl (k-1));
new(p);p^.num:=y;p^.next:=head[i]^.next;head[i]^.next:=p;
end;
fillchar(used,sizeof(used),false);
fillchar(d,sizeof(d),0);
dfs(1 shl m-1,0);
if not used[0] then writeln('The patient will be dead.') else writeln(d[0]);
close(input);close(output);
end.
请大牛看看。或者能不能提供第五组数据?