起诉抚养费程序及费用:turbo pascal编程 帮我看一下我编的哪错了

来源:百度文库 编辑:高考问答 时间:2024/05/12 16:32:55
const maxn=10;
var j,k,i,n:longint;
a:array[1..maxn]of longint;

procedure print;
var i:longint;
begin
for i:=1 to n do
write(a[i]);
end;

function place:boolean;
var i,j,n:longint;
begin
if place:=true then for i:=2 to n do
for j:=1 to i-1 do
if (a[i]=a[j])then begin place:=false;break;end;
end;

procedure try(dep:longint);
var i,n:longint;
begin
if place:=true then
begin
if dep>n then print
else
for i:=1 to n do
begin
a[dep]:=i;
try(dep+1);
end;
end;
end;
begin
read(n);
try(1);
end.
!啊~~~~
能在pascal里运行吗
是4*4的方格摆棋子
棋子在横着、竖着、斜着都不可以有其他的棋子
总共是4枚棋子
打印所有的摆法

递归是吧.
我没有机器上机, 但我可以肯定你function place 这部分有问题. 注意第一句 if place=true then... 把它删去试试吧.
还有第二个if place: =true then 应改成if place=true then

你的问题应该是N皇后问题吧

你的程序从头到尾都是错的

可以有回溯算法解决这个问题
也可以用递推
你去 www.bxgz.cn/sss
上看看吧

program checker;
const
maxn=13;
var
fin,fout:text;
ans:array[1..3,1..maxn]of byte;
s:array[1..maxn]of byte;
pre,next:array[0..maxn+1]of byte;
pie:array[2..maxn*2]of boolean;
na:array[1-maxn..maxn-1]of boolean;
n,i,j,total:longint;
procedure search(x:byte);
var
y:byte;
begin
y:=0;
repeat
y:=next[y];
if y>n then exit;
if not pie[x+y] and not na[x-y] then begin
pie[x+y]:=true;na[x-y]:=true;
pre[next[y]]:=pre[y];next[pre[y]]:=next[y];
s[x]:=y;
if x=n then begin
inc(total);
if total<4 then ans[total]:=s;
end
else
search(x+1);
pie[x+y]:=false;na[x-y]:=false;
pre[next[y]]:=y;next[pre[y]]:=y;
end;
until false;
end;
procedure start(y:byte);
begin
if not pie[1+y] and not na[1-y] then begin //Here it's true of course
pie[1+y]:=true;na[1-y]:=true;
pre[next[y]]:=pre[y];next[pre[y]]:=next[y];
s[1]:=y;
search(2);
pie[1+y]:=false;na[1-y]:=false;
pre[next[y]]:=y;next[pre[y]]:=y;
end;
end;
begin
read(n);

for i:=1 to n do begin
pre[i]:=i-1;next[i]:=i+1;
end;
pre[n+1]:=n;next[0]:=1;
if n=6 then
for i:=1 to 6 do
start(i)
else begin
for i:=1 to n shr 1 do
start(i);
total:=total*2;
if odd(n) then start(n shr 1+1);
end;

for i:=1 to 3 do begin
for j:=1 to n-1 do
write(ans[i,j],' ');
writeln(ans[i,n]);
end;
writeln(total);
end.

用这个吧。这个是在USACO上过了的N皇后。最大可以做到13皇后。1秒钟。