21127_Crabbles

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

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

Pro.ID

21127

Title

Crabbles

Title链接

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

AC

5

Submit

33

Ratio

15.15%

时间&空间限制

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

    Jennifer is practicing for a Crabbles tournament. She pulls out a handful of Crabbles tiles out of a bag, and tries to form the word with the highest possible score. Each tile contains a letter (used to form the word) and a number (its score value). She can use each tile at most once in her word, and she is not required to use every tile. The word that she forms must appear in her dictionary. Her score is the sum of the values of the tiles used in the word.

    Note that in Crabbles, different tiles with the same letter may have different score values.

    To check her work, Jennifer would like a program to tell her the maximum score possible for the set of tiles. Your task is to write this program.

    输入

    The first line contains an integer 1 ≤ N ≤ 100,000 indicating the number of words in the dictionary. N lines follow, with one dictionary word on each line. Each dictionary word consists of only lowercase letters. The following line contains an integer 1 ≤ M ≤ 1000 indicating the number of Crabbles hands Jennifer wants to play. M hands follow. Each hand begins with a line containing an integer 1 ≤ P ≤ 10 indicating the number of tiles in the hand. This is followed by P lines, one for each tile. Each of these lines consists of a lowercase letter (the letter on the tile), a space, and an integer 0 ≤ V ≤ 10 (the value of the tile).

    输出

    Description

    Jennifer is practicing for a Crabbles tournament. She pulls out a handful of Crabbles tiles out of a bag, and tries to form the word with the highest possible score. Each tile contains a letter (used to form the word) and a number (its score value). She can use each tile at most once in her word, and she is not required to use every tile. The word that she forms must appear in her dictionary. Her score is the sum of the values of the tiles used in the word.

    Note that in Crabbles, different tiles with the same letter may have different score values.

    To check her work, Jennifer would like a program to tell her the maximum score possible for the set of tiles. Your task is to write this program.

    Input

    The first line contains an integer 1 ≤ N ≤ 100,000 indicating the number of words in the dictionary. N lines follow, with one dictionary word on each line. Each dictionary word consists of only lowercase letters. The following line contains an integer 1 ≤ M ≤ 1000 indicating the number of Crabbles hands Jennifer wants to play. M hands follow. Each hand begins with a line containing an integer 1 ≤ P ≤ 10 indicating the number of tiles in the hand. This is followed by P lines, one for each tile. Each of these lines consists of a lowercase letter (the letter on the tile), a space, and an integer 0 ≤ V ≤ 10 (the value of the tile).

    Output

    For each hand in the input, output a line containing the maximum score possible with that hand.

    Sample Input

    2
    abcd
    hgfe
    1
    10
    a 1
    b 2
    c 3
    d 4
    e 5
    f 6
    g 7
    h 8
    i 9
    j 10

    Sample Output

    26

    Source

    样例输入

    2
    abcd
    hgfe
    1
    10
    a 1
    b 2
    c 3
    d 4
    e 5
    f 6
    g 7
    h 8
    i 9
    j 10

    样例输出

    26

    作者


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部