作业帮 > 综合 > 作业

新手求指导,深度优先搜索的问题

来源:学生作业帮 编辑:神马作文网作业帮 分类:综合作业 时间:2024/11/17 13:07:51
新手求指导,深度优先搜索的问题
const
data:array[1..9,0..5] of longint=
((4,1,2,4,5,0),
(3,1,2,3,0,0),
(4,2,3,5,6,0),
(3,1,4,7,0,0),
(5,2,4,5,6,8),
(3,3,6,9,0,0),
(4,4,5,7,8,0),
(3,7,8,9,0,0),
(4,5,6,8,9,0));
var
a,b:array[1..9] of longint;
x,i:longint;
ans:string;
procedure outit;
var
i,j:longint;
begin
for i:=1 to 9 do
if a[i] mod 40 then exit;
ans:='';
for i:=1 to 9 do
for j:=1 to b[i] do
ans:=ans+chr(i+48)+' ';
delete(ans,length(ans),1);
writeln(ans);close(input);close(output);halt;
end;
procedure dfs(depth:longint);
var
i,j:longint;
begin
if depth=10 then outit
else
begin
for i:=0 to 3 do
begin
b[depth]:=i;
for j:=1 to data[depth,0] do
inc(a[data[depth,j]],i);
dfs(depth+1);
for j:=1 to data[depth,0] do
dec(a[data[depth,j]],i);
end;
end;
end;
begin
assign(input,'clocks.in');reset(input);
assign(output,'clocks.out');rewrite(output);
for i:=1 to 9 do
begin
read(x);a[i]:=x div 3;
end;
dfs(1);
end.
新手求指导,深度优先搜索的问题
啊,USACO上的题啊,看我给的参考资料链接吧,讲得很详细.