21961_GrowingStrings

2022-5-16 18:20| 发布者: Hocassian| 查看: 33| 评论: 0|原作者: 肇庆学院ACM合集

摘要:
C:\Users\Administrator\Downloads\2019-10-12-10-14-4-89505996159100-Problem List-采集的数据-后羿采集器.html

Pro.ID

21961

Title

Growing Strings

Title链接

http://10.20.2.8/oj/exercise/problem?problem_id=21961

AC

0

Submit

0

Ratio

-

时间&空间限制

  • Time Limit: 10000/5000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    Gene and Gina have a particular kind of farm. Instead of growing animals and vegetables, as it is usually the case in regular farms, they grow strings. A string is a sequence of characters. Strings have the particularity that, as they grow, they add characters to the left and/or to the right of themselves, but they never lose characters, nor insert new characters in the middle.

    Gene and Gina have a collection of photos of some strings at different times during their growth. The problem is that the collection is not annotated, so they forgot to which string each photo belongs to. They want to put together a wall to illustrate strings growing procedures, but they need your help to find an appropriate sequence of photos.

    Each photo illustrates a string. The sequence of photos must be such that if si comes immediately before si+1 in the sequence, then si+1 is a string that may have grown from si (i.e., si appears as a consecutive substring of si+1). Also, they do not want to use repeated pictures, so all strings in the sequence must be different.

    Given a set of strings representing all available photos, your job is to calculate the size of the largest sequence they can produce following the guidelines above.

    输入

    Each test case is given using several lines. The first line contains an integer N representing the number of strings in the set (1 ≤ N ≤ 104). Each of the following N lines contains a different non-empty string of at most 1000 lowercase letters of the English alphabet. Within each test case, the sum of the lengths of all strings is at most 106.

    The last test case is followed by a line containing one zero.

    输出

    Description

    Gene and Gina have a particular kind of farm. Instead of growing animals and vegetables, as it is usually the case in regular farms, they grow strings. A string is a sequence of characters. Strings have the particularity that, as they grow, they add characters to the left and/or to the right of themselves, but they never lose characters, nor insert new characters in the middle.

    Gene and Gina have a collection of photos of some strings at different times during their growth. The problem is that the collection is not annotated, so they forgot to which string each photo belongs to. They want to put together a wall to illustrate strings growing procedures, but they need your help to find an appropriate sequence of photos.

    Each photo illustrates a string. The sequence of photos must be such that if si comes immediately before si+1 in the sequence, then si+1 is a string that may have grown from si (i.e., si appears as a consecutive substring of si+1). Also, they do not want to use repeated pictures, so all strings in the sequence must be different.

    Given a set of strings representing all available photos, your job is to calculate the size of the largest sequence they can produce following the guidelines above.

    Input

    Each test case is given using several lines. The first line contains an integer N representing the number of strings in the set (1 ≤ N ≤ 104). Each of the following N lines contains a different non-empty string of at most 1000 lowercase letters of the English alphabet. Within each test case, the sum of the lengths of all strings is at most 106.

    The last test case is followed by a line containing one zero.

    Output

    For each test case output a single line with a single integer representing the size of the largest sequence of photos that can be produced.

    Sample Input

    6
    plant
    ant
    cant
    decant
    deca
    an
    2
    supercalifragilisticexpialidocious
    rag
    0

    Sample Output

    4
    2

    Source

    样例输入

    6
    plant
    ant
    cant
    decant
    deca
    an
    2
    supercalifragilisticexpialidocious
    rag
    0

    样例输出

    4
    2

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部