比赛 |
NOIP_1 |
评测结果 |
WWWWW |
题目名称 |
画海岛地图 |
最终得分 |
0 |
用户昵称 |
苏轼 |
运行时间 |
0.000 s |
代码语言 |
Pascal |
内存使用 |
0.00 MiB |
提交时间 |
2008-10-12 10:43:56 |
显示代码纯文本
program cch(input,output);
type
sz=array[1..10,1..10] of char;
var
n:integer;
tot,ch:longint;
a,b:array[0..10,0..10] of integer;
c:array[1..10] of integer;
d:array[1..1000,1..10] of integer;
ans:sz;
procedure init;
var
i,x,j,tmp:integer;
begin
assign(input,'island.in');
assign(output,'island.out');
reset(input);
rewrite(output);
readln(n);
for i:=1 to n do
begin
a[i,0]:=0;
b[i,0]:=0;
end;
for i:=1 to n do
begin
read(x);
while x<>0 do
begin
inc(a[i,0]);
a[i,a[i,0]]:=x;
read(x);
end;
tmp:=0;
for j:=1 to a[i,0] do inc(tmp,a[i,j]);
c[i]:=n-tmp-(a[i,0]-1);
end;
for i:=1 to n do
begin
read(x);
while x<>0 do
begin
inc(b[i,0]);
b[i,b[i,0]]:=x;
read(x);
end;
end;
end;
procedure combit(k,q,t:integer);
var
i:integer;
begin
if k=t+1 then
begin
inc(ch);
exit;
end;
for i:=0 to q do
begin
d[ch,k]:=i;
combit(k+1,q-i,t);
end;
end;
function check(ans:sz):boolean;
var
i,j,q:integer;
begin
for i:=1 to n do
begin
q:=1;
while q<=n do
begin
while (q<=n)and(ans[q,i]=' ') do inc(q);
for j:=1 to b[i,0] do
begin
if (ans[q,i]=' ')or(q>n) then exit(false);
inc(q);
end;
end;
end;
check:=true;
end;
procedure print;
var
i,j:integer;
begin
writeln(tot);
for i:=1 to n do
begin
for j:=1 to n do
write(a[i,j]);
writeln;
end;
end;
procedure search(k:integer);
var
i,j,w,r:integer;
begin
if k=n+1 then
begin
if check(ans) then
begin
inc(tot);
print;
end;
exit;
end;
ch:=1;
combit(1,c[k],a[k,0]);
for i:=1 to ch do
begin
w:=0;
for j:=1 to a[k,0] do
begin
for r:=1 to d[i,j] do
begin
inc(w);
ans[k,w]:=' ';
end;
for r:=1 to a[k,j] do
begin
inc(w);
ans[k,w]:='*';
end;
inc(w); ans[k,w]:=' ';
end;
for j:=1 to n-w do ans[k,j]:=' ';
search(k+1);
end;
end;
begin
init;
tot:=0;
search(1);
close(input);
close(output);
end.