比赛 noip_6 评测结果 AAAAAAAAAA
题目名称 词链 最终得分 100
用户昵称 苏轼 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-10-26 11:01:46
显示代码纯文本
program cch(input,output);
var
 i,j,n,ans,ch,q:integer;
 a:array[1..10000] of string;
 father:array[0..10000] of integer;
 child:array[0..10000,0..100] of integer;

procedure search(k:integer);
var
 i:integer;
begin
 if ch>ans then ans:=ch;
 for i:=1 to child[k,0] do
  begin
   inc(ch);
   search(child[k,i]);
   dec(ch);
  end;
end;


begin
 assign(input,'link.in');
 assign(output,'link.out');
 reset(input);
 rewrite(output);
 readln(n);
 for i:=1 to n do readln(a[i]);
 for i:=1 to n do child[i,0]:=0;
 for i:=1 to n do
  begin
   j:=i-1;
   while (j>0)and(pos(a[j],a[i])=0) do dec(j);
   father[i]:=j;
   inc(child[j,0]);
   child[j,child[j,0]]:=i;
  end;
 ans:=0;
 for i:=1 to n do
  if father[i]=0 then
   begin
    ch:=1;
    search(i);
   end;
 write(ans);
 close(input);
 close(output);
end.