主题:usaco 1.4 checker 超时
输入13 超时
源程序:
program checker(input,output);
var
a:array[0..15]of boolean;
b:array[-15..15]of boolean;
c:array[0..30]of boolean;
num:array[0..15]of integer;
n:integer;
sum:longint;
time:longint;
procedure try(ceng:integer);
var i:integer;
begin
if ceng>n then
begin
inc(sum);
if sum<=3 then
begin
for i:=1 to n-1 do write(num[i],' ');
writeln(num[n]);
end;
end
else for i:=1 to n do
if (not a[i])and(not b[ceng-i])and(not c[ceng+i]) then
begin
a[i]:=true;
b[ceng-i]:=true;
c[ceng+i]:=true;
num[ceng]:=i;
try(ceng+1);
a[i]:=false;
b[ceng-i]:=false;
c[ceng+i]:=false;
num[ceng]:=0;
end;
end;
begin
assign(input,'checker.in');
assign(output,'checker.out');
reset(input);
rewrite(output);
{ time:=meml[$40:$6c];}
readln(n);
try(1);
writeln(sum);
{ writeln((meml[$40:$6c]-time)/18.4:0:2);}
close(input);
close(output);
end.
帮我改一下
源程序:
program checker(input,output);
var
a:array[0..15]of boolean;
b:array[-15..15]of boolean;
c:array[0..30]of boolean;
num:array[0..15]of integer;
n:integer;
sum:longint;
time:longint;
procedure try(ceng:integer);
var i:integer;
begin
if ceng>n then
begin
inc(sum);
if sum<=3 then
begin
for i:=1 to n-1 do write(num[i],' ');
writeln(num[n]);
end;
end
else for i:=1 to n do
if (not a[i])and(not b[ceng-i])and(not c[ceng+i]) then
begin
a[i]:=true;
b[ceng-i]:=true;
c[ceng+i]:=true;
num[ceng]:=i;
try(ceng+1);
a[i]:=false;
b[ceng-i]:=false;
c[ceng+i]:=false;
num[ceng]:=0;
end;
end;
begin
assign(input,'checker.in');
assign(output,'checker.out');
reset(input);
rewrite(output);
{ time:=meml[$40:$6c];}
readln(n);
try(1);
writeln(sum);
{ writeln((meml[$40:$6c]-time)/18.4:0:2);}
close(input);
close(output);
end.
帮我改一下