新手求指导,深度优先搜索的问题
来源:学生作业帮 编辑:神马作文网作业帮 分类:综合作业 时间: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.
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上的题啊,看我给的参考资料链接吧,讲得很详细.
深度优先搜索和广度优先搜索、A星算法三种算法的区别和联系?
(求解C程序高手)用正向表存储图的数据,并实现图的深度优先搜索和广度优先搜索.
matlab新手,求大神指导,
python 新手求指导习题.
数据结构问题,有关深度优先遍历的,第13小题.我知道abc三个选项不对,但是觉得d也不对.总觉得应该是aedcfb求大神
天文新手,买望远镜,求指导~
量子力学,狄拉克符号,新手求指导
软件测试的优先策略,一种是深度优先策略,另一种是
邻接矩阵、邻接表表示图时的深度优先序列、广度优先序列
VB里面循环语句怎么用 下面的公式怎么编辑?新手求指导啊
Altium Designer 6.9器件库里没有想要的电阻,怎么办,新手求指导.
天文新手,想购买望远镜,求大神进来指导~