noi4_7_8468[单词序列]

Posted love_saber

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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[单词序列]的主要内容,如果未能解决你的问题,请参考以下文章

noi4_1_1999[日志排序]

noi4_1_1754[字符串数组排序问题]

python_如何统计序列中元素

5_CentOS 7 基本命令操作(附单词)

What's new in C# 7.0

What's new in C# 7.0