比赛 noip_6 评测结果 AAAAAAAAAA
题目名称 词链 最终得分 100
用户昵称 lc 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-10-08 21:32:44
显示代码纯文本
program noip5_3;
 var
    s:array[1..10000] of string;
    f:array[1..10000] of integer;
    n,ans:integer;


procedure init;
 var
    i:integer;
 begin
  readln(n);
  for i:=1 to n do
   readln(s[i]);
 end;

procedure qsort(l,r:integer);
 var
    i,j:integer;
    x,temp:string;
 begin
  i:=l; j:=r; x:=s[(i+j) div 2];
 Repeat
  While s[i]<x do inc(i);
  While s[j]>x do dec(j);
  if i<=j
  then begin
       temp:=s[i];
       s[i]:=s[j];
       s[j]:=temp;
       inc(i); dec(j);
       end;
 Until i>j;
 if j>l then qsort(l,j);
 if i<r then qsort(i,r);
 end;


procedure main;
 var
    i,j,k:integer;
 begin
  qsort(1,n);
  for i:=1 to n do
  begin
    k:=0; f[i]:=1;
   for j:=i-1 downto 1 do
   if (pos(s[j],s[i])=1)
   then begin
        k:=j; break
        end;
   if k<>0 then inc(f[i],f[k]);
  end;
 for i:=1 to n do
 if f[i]>ans then ans:=f[i];
 writeln(ans);
 end;

begin
 assign(input,'link.in');
 assign(output,'link.out');
 reset(input); rewrite(output);
 init;
 main;
 close(input); close(output);
end.