zoukankan      html  css  js  c++  java
  • 2.3.1 Longest Prefix

    Longest Prefix
    IOI'96

    The structure of some biological objects is represented by the sequence of their constituents, where each part is denote by an uppercase letter. Biologists are interested in decomposing a long sequence into shorter ones called primitives.

    We say that a sequence S can be composed from a given set of primitives P if there is a some sequence of (possibly repeated) primitives from the set whose concatenation equals S. Not necessarily all primitives need be present. For instance the sequence ABABACABAABcan be composed from the set of primitives

    	   {A, AB, BA, CA, BBC}
    

    The first K characters of S are the prefix of S with length K. Write a program which accepts as input a set of primitives and a sequence of constituents and then computes the length of the longest prefix that can be composed from primitives.

    PROGRAM NAME: prefix

    INPUT FORMAT

    First, the input file contains the list (length 1..200) of primitives (length 1..10) expressed as a series of space-separated strings of upper-case characters on one or more lines. The list of primitives is terminated by a line that contains nothing more than a period (`.'). No primitive appears twice in the list. Then, the input file contains a sequence S (length 1..200,000) expressed as one or more lines, none of which exceeds 76 letters in length. The "newlines" (line terminators) are not part of the string S.

    SAMPLE INPUT (file prefix.in)

    A AB BA CA BBC
    .
    ABABACABAABC
    

    OUTPUT FORMAT

    A single line containing an integer that is the length of the longest prefix that can be composed from the set P.

    SAMPLE OUTPUT (file prefix.out)

    11
    
    {
    ID: makeeca1
    PROG: prefix
    LANG: PASCAL
    }
    program prefix;
    const cht=['A'..'Z'];
    var i,j,n,t:longint;
        tmp:char;
        temp,s:ansistring;
        a:array[1..200]of string[10];
        f:array[0..200000]of boolean;
    begin
      assign(input,'prefix.in');reset(input);
      assign(output,'prefix.out');rewrite(output);
      t:=1;
      while tmp<>'.'  do begin
        read(tmp);
        if tmp in cht then a[t]:=a[t]+tmp
                      else inc(t);
      end;
      while not eof do begin
        readln(temp);
        s:=s+temp;
      end;
      dec(t);
      n:=length(s);
      f[0]:=true;
      for i:=1 to n do
        for j:=1 to t do
          if (length(a[j])<=i)and(copy(s,i-length(a[j])+1,length(a[j]))=a[j])
          and(f[i-length(a[j])])  then begin
            f[i]:=true;
            break;
          end;
      for i:=n downto 0 do if f[i] then break;
      writeln(i);
      close(input);
      close(output);
    end.
  • 相关阅读:
    L05 Laravel 教程 电商实战
    laravel 5.5 登录验证码 captcha 引入
    thinkphp 清理runtime缓存的方法, 清理指定目录
    艾伟也谈项目管理,项目经理要如何看待技术? 狼人:
    艾伟也谈项目管理,带领团队发挥最大潜能的10个技巧 狼人:
    艾伟也谈项目管理,聊聊我们团队的绩效管理 狼人:
    艾伟也谈项目管理,创建敏捷团队 狼人:
    艾伟也谈项目管理,多任务让你走得更慢 狼人:
    艾伟也谈项目管理,项目经理的思维批判 狼人:
    艾伟也谈项目管理,创业公司技术选型参考 狼人:
  • 原文地址:https://www.cnblogs.com/makeecat/p/3274578.html
Copyright © 2011-2022 走看看