终于搞清楚了Dancing links是怎么写的了,并用P和C各写了一遍
program poj_3740;
var
l,r,u,d,ch:array[0..10000]of longint;
lin,col,size,o:array[0..1000]of longint;
mx,bj,st,i,j,m,n,x,head:longint;
procedure origin(n,m:longint);
begin
for i:=1 to m do begin
l[i]:=i-1; r[i]:=i+1; u[i]:=i; d[i]:=i;
end; l[0]:=n; r[0]:=1; r[m]:=0;
for i:=1 to n do begin
l[m+i]:=m+i; r[m+i]:=m+i;
end; st:=m+n;
end;
procedure link(x,y,xx,yy:longint);
begin
inc(st); lin[st]:=x; col[st]:=y;
l[st]:=l[x]; r[st]:=x; l[r[st]]:=st; r[l[st]]:=st;
u[st]:=u[y]; d[st]:=y; u[d[st]]:=st; d[u[st]]:=st;
inc(size[y]);
end;
procedure init;
begin
origin(n,m);
for i:=1 to n do
for j:=1 to m do begin
read(x);
if x=1 then link(i+m,j,i,j);
end;
end;
procedure remove(c:longint);
begin if c=0 then exit;
l[r[c]]:=l[c]; r[l[c]]:=r[c];
i:=d[c];while i<>c do begin
j:=r[i];while j<>i do begin
u[d[j]]:=u[j];
d[u[j]]:=d[j];
dec(size[col[j]]);
j:=r[j];end;
i:=d[i];end;
end;
procedure resume(c:longint);
begin
l[r[c]]:=c; r[l[c]]:=c;
i:=d[c];while i<>c do begin
j:=r[i];while j<>i do begin
inc(size[col[j]]);
d[u[j]]:=j;
u[d[j]]:=j;
j:=r[j];end;
i:=d[i];end;
end;
function dfs(k:integer):boolean;
var ss:integer=maxint; i,j,c:integer;
begin
if r[head]=head then exit(true);
i:=r[head];c:=head;while i<>head do begin
if size[i]<ss then begin ss:=size[i]; c:=i; end;
i:=r[i]; end;
remove(c);
i:=d[c];while i<>c do begin
o[k]:=i; //len:=k;
j:=r[i];while j<>i do begin
remove(col[j]);
j:=r[j]; end;
if dfs(k+1) then exit(true);
j:=l[i];while j<>i do begin
resume(col[j]);
j:=l[j];end;
i:=d[i];end;
resume(c);
exit;
end;
begin
while not eof do begin
readln(m,n);
init;
if dfs(0) then writeln('Find') else writeln('unfind');
end;
end.
这是PASCAL的