10271_Jukebox

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

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

Pro.ID

10271

Title

Jukebox

Title链接

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

AC

0

Submit

0

Ratio

-

时间&空间限制

  • Time Limit: 2000/1000 MS (Java/Others)     Memory Limit: 65536/65536 K (Java/Others)
  • 描述

    The ICPC judges are preparing a party for the opening ceremony. For the party, they intend to add a playlist with some songs to the jukebox software (a simple MP3 player). However, there are so many songs in the computer that it is difficult to find the ones they want to add. As a consequence, they need to use the search feature many times.

    In this jukebox, when you search for a string s, the software returns every music whose title or artist name contains s as a substring. String s is a substring of string t if t contains all characters of s as a contiguous sequence (for example, 'bc' is a substring of 'abcd', but 'ac' is not). To save their precious time, while looking for a song, they always use one of the song's golden string, i.e. one of the shortest strings for which the search returns as a result only the song they want.

    In the example above, a possible golden string for the song 'johnnatan' is 'ta'. Note that 'ta' is not a substring of the name of another song nor a substring of the artist of another song. Note also that there is no string of size equal to 1 that could identify uniquely the song 'johnnatan'.

    They discovered that if they remove the artist fields from some of the songs they can get even smaller golden strings. For the song 'john', there is no golden string. However, if one removes the artist field from all other songs, the string 'c' becomes the golden string for the song 'john'.

    Given the song list (each song with name and artist), your job is to determine the minimum sum of the golden string sizes for all songs that can be obtained if one is allowed to remove some of the artist fields. In the figure above you can see a possible best result with the golden strings in bold. The minimum sum of the golden string sizes in this case is 10.

    输入

    The input contains several test cases. The first line of each test case contains one integer N ( 1 ≤ N 30 ), which indicates the number of songs. Following there will be N pairs of lines (2 * N lines), one pair for each song. The first line of a pair will contain the song name, the second line will contain the artist name. Both artist and song names are strings containing only lower case letters or underlines and having at least 1 and at most 30 characters. There will be at most 6 different artists in the list.

    The end of the input is given by N = 0.

    输出

    Description

    The ICPC judges are preparing a party for the opening ceremony. For the party, they intend to add a playlist with some songs to the jukebox software (a simple MP3 player). However, there are so many songs in the computer that it is difficult to find the ones they want to add. As a consequence, they need to use the search feature many times.

    In this jukebox, when you search for a string s, the software returns every music whose title or artist name contains s as a substring. String s is a substring of string t if t contains all characters of s as a contiguous sequence (for example, 'bc' is a substring of 'abcd', but 'ac' is not). To save their precious time, while looking for a song, they always use one of the song's golden string, i.e. one of the shortest strings for which the search returns as a result only the song they want.

    In the example above, a possible golden string for the song 'johnnatan' is 'ta'. Note that 'ta' is not a substring of the name of another song nor a substring of the artist of another song. Note also that there is no string of size equal to 1 that could identify uniquely the song 'johnnatan'.

    They discovered that if they remove the artist fields from some of the songs they can get even smaller golden strings. For the song 'john', there is no golden string. However, if one removes the artist field from all other songs, the string 'c' becomes the golden string for the song 'john'.

    Given the song list (each song with name and artist), your job is to determine the minimum sum of the golden string sizes for all songs that can be obtained if one is allowed to remove some of the artist fields. In the figure above you can see a possible best result with the golden strings in bold. The minimum sum of the golden string sizes in this case is 10.

    Input

    The input contains several test cases. The first line of each test case contains one integer N ( 1 ≤ N 30 ), which indicates the number of songs. Following there will be N pairs of lines (2 * N lines), one pair for each song. The first line of a pair will contain the song name, the second line will contain the artist name. Both artist and song names are strings containing only lower case letters or underlines and having at least 1 and at most 30 characters. There will be at most 6 different artists in the list.

    The end of the input is given by N = 0.

    Output

    For each test case your program must output one single line with the minimum sum of the golden string sizes. You may assume that there will always be a solution.

    Sample Input

    8
    a_flor
    los_hermanos
    anna_julia
    los_hermanos
    quem_sabe
    los_hermanos
    pierrot
    los_hermanos
    azedume
    los_hermanos
    johnny
    massacration
    johnnatan
    massacration
    john
    massacration
    4
    c
    axc
    b
    axc
    d
    cc
    xc
    cc
    0

    Sample Output

    10
    5

    Source

    样例输入

    8
    a_flor
    los_hermanos
    anna_julia
    los_hermanos
    quem_sabe
    los_hermanos
    pierrot
    los_hermanos
    azedume
    los_hermanos
    johnny
    massacration
    johnnatan
    massacration
    john
    massacration
    4
    c
    axc
    b
    axc
    d
    cc
    xc
    cc
    0

    样例输出

    10
    5

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部