记录编号 42787 评测结果 AATATATA
题目名称 [ZSTU 2579] 著名医生的药方 最终得分 62
用户昵称 Gravatarwangmengyuan 是否通过 未通过
代码语言 Pascal 运行时间 4.514 s
提交时间 2012-09-29 15:43:54 内存使用 3.50 MiB
显示代码纯文本
    var
    a,b,c,d,e,m,n,p,ooo:longint;
    l:array[0..1000,0..1000]of longint;
    hx:array[0..500]of longint;
    k,lz,o:array[0..1000]of longint;
    procedure dfs1(x:longint);
    var
    y,z,i,j,u,h,r:longint;
    begin
    if x=p+1 then
    begin


    h:=0;
    for i:=1 to p do
    if i>2 then
    for j:=i to p do
    for u:=1 to lz[o[i-2]] do
    if o[j]=l[o[i-2],u] then
    h:=1;




    if h=0 then

    ooo:=ooo+1;


    end

    else
    begin
    for y:=1 to lz[o[x-1]] do
    begin
    if k[x]<>0 then
    if (l[o[x-1],y]=k[x])and(hx[k[x]]=0) then
    begin
    o[x]:=k[x];
    hx[o[x]]:=1;
    dfs1(x+1);
    hx[o[x]]:=0;
    end;
    if (k[x]=0)and(hx[l[o[x-1],y]]=0) then
    begin
    o[x]:=l[o[x-1],y];
    hx[o[x]]:=1;
    dfs1(x+1);
    hx[o[x]]:=0;
    end;
    end;
    end;
    end;
    procedure dfs2(x:longint);
    var
    y,z,i,j,u,h,r,q:longint;
    begin
    if x=p+1 then
    begin


    h:=0;
    for i:=1 to p do
    if i>2 then
    for j:=i to p do
    for u:=1 to lz[o[i-2]] do
    if o[j]=l[o[i-2],u] then
    h:=1;




    if h=0 then
     begin
     for q:=1 to p-1 do
     write(o[q],' ');
     write(o[p]);
     writeln;
     end;


    end

    else
    begin
    for y:=1 to lz[o[x-1]] do
    begin
    if k[x]<>0 then
    if (l[o[x-1],y]=k[x])and(hx[k[x]]=0) then
    begin
    o[x]:=k[x];
    hx[o[x]]:=1;
    dfs2(x+1);
    hx[o[x]]:=0;
    end;
    if (k[x]=0)and(hx[l[o[x-1],y]]=0) then
    begin
    o[x]:=l[o[x-1],y];
    hx[o[x]]:=1;
    dfs2(x+1);
    hx[o[x]]:=0;
    end;
    end;
    end;
    end;
    begin
    assign(input,'doctor.in');
    assign(output,'doctor.out');
    reset(input);
    rewrite(output);
    readln(n);
    for a:=1 to n do
    begin
    while not eoln do
    begin
    inc(lz[a]);
    read(l[a,lz[a]]);
    end;
    readln;
    end;
    readln(p);
    for a:=1 to p do
    readln(k[a]);
    for a:=1 to n do
    begin
    o[1]:=a;
    hx[a]:=1;
    dfs1(2);
    hx[a]:=0;
    end;
    writeln(ooo);
    fillchar(hx,sizeof(hx),0);
     for a:=1 to n do
    begin
    o[1]:=a;
    hx[a]:=1;
    dfs2(2);
    hx[a]:=0;
    end;
    close(input);
    close(output);
    end.