比赛 noip_6 评测结果 WWTTTTTTTT
题目名称 词链 最终得分 0
用户昵称 maxiem 运行时间 0.000 s
代码语言 Pascal 内存使用 0.00 MiB
提交时间 2008-10-08 21:49:16
显示代码纯文本
program link;
var
  d:array [1..50] of record
    n:integer;
    s:array [1..5000] of string
  end;
  j,t,i,max,n:integer;
  h:array [0..50] of integer;
  tmp,b,cb:string;
procedure go(l:integer);
begin
  for i:=1 to d[h[l]].n do begin
    if copy(d[h[l]].s[i],1,length(b))=b then begin
      cb:=b;b:=d[h[l]].s[i];
      go(l+1);
      b:=cb;
    end
    else if copy(d[h[l]].s[i],1,length(b))>b then break;
  end;
  if l>max then max:=l;
end;
begin
  max:=-maxint;
  for i:=1 to 50 do d[i].n:=0;
  fillchar (h,sizeof(h),0);
  assign (input,'link.in');
  reset (input);
  readln (n);
  for i:=1 to n do begin
    readln (tmp);
    inc(d[length(tmp)].n);
    d[length(tmp)].s[d[length(tmp)].n]:=tmp;
    inc(h[0]);
    h[h[0]]:=length(tmp);
  end;
  for i:=1 to h[0]-1 do for j:=i+1 to h[0] do if h[i]>h[j] then begin
    t:=h[i];h[i]:=h[j];h[j]:=t;
  end;
  close (input);
  assign (output,'link.out');
  rewrite (output);
  for i:=1 to d[h[1]].n do begin
    b:=d[h[1]].s[i];
    go(2);
  end;
  writeln (max);
  close (output);
end.