首页 > 代码库 > noi4_7_8468[单词序列]

noi4_7_8468[单词序列]

爆搜都能过……我佩服它的数据规模

uses math;var f:array[1..10000] of boolean;    a:array[1..100] of string[6];    n:longint;    start,final:string[6];    ans:longint;function cj(a,b:string):boolean;var k,i:longint;begin k:=0; for i:=1 to length(a) do  if a[i]<>b[i] then inc(k); if k=1 then exit(true); exit(false);end;procedure dfs(s:string; step:longint);var i:longint;begin if cj(s,final) then  begin   ans:=min(ans,step);   exit;  end; for i:=1 to n do  if (f[i])and(cj(s,a[i])) then   begin    f[i]:=false;    dfs(a[i],step+1);    f[i]:=true;   end;end;procedure scanf;var s:string[155];    k:longint;begin readln(s); k:=pos(‘ ‘,s); start:=copy(s,1,k-1); final:=copy(s,k+1,length(s)-k); readln(s); s:=s+‘ ‘; n:=0; while s<>‘‘ do  begin   k:=pos(‘ ‘,s);   inc(n);   a[n]:=copy(s,1,k-1);   delete(s,1,k);  end;end;procedure work;begin fillchar(f,sizeof(f),true); ans:=100; dfs(start,2); write(ans mod 100);end;begin scanf; work;end.

noi4_7_8468[单词序列]