22029_Ring

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

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

Pro.ID

22029

Title

Ring

Title链接

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

AC

2

Submit

13

Ratio

15.38%

时间&空间限制

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

    For the hope of a forever love, Steven is planning to send a ring to Jane with a romantic string engraved on. The string's length should not exceed N. The careful Steven knows Jane so deeply that he knows her favorite words, such as "love", "forever". Also, he knows the value of each word. The higher value a word has the more joy Jane will get when see it.

    The weight of a word is defined as its appeared times in the romantic string multiply by its value, while the weight of the romantic string is defined as the sum of all words' weight. You should output the string making its weight maximal.

    输入

    The input consists of several test cases. The first line of input consists of an integer T, indicating the number of test cases. Each test case starts with a line consisting of two integers: N, M, indicating the romantic string's length and the number of Jane's favorite words. Each of the following M lines consists of a favorite word Si. The last line of each test case consists of M integers, while the i-th number Hi indicates the value of Si.

    T ≤ 15

    0 < N ≤ 50, 0 < M ≤ 100.

    The length of each word is less than 11 and bigger than 0.

    1 ≤ Hi ≤ 100.

    All the words in the input are different.

    All the words just consist of 'a' - 'z'.

    输出

    Description

    For the hope of a forever love, Steven is planning to send a ring to Jane with a romantic string engraved on. The string's length should not exceed N. The careful Steven knows Jane so deeply that he knows her favorite words, such as "love", "forever". Also, he knows the value of each word. The higher value a word has the more joy Jane will get when see it.

    The weight of a word is defined as its appeared times in the romantic string multiply by its value, while the weight of the romantic string is defined as the sum of all words' weight. You should output the string making its weight maximal.

    Input

    The input consists of several test cases. The first line of input consists of an integer T, indicating the number of test cases. Each test case starts with a line consisting of two integers: N, M, indicating the romantic string's length and the number of Jane's favorite words. Each of the following M lines consists of a favorite word Si. The last line of each test case consists of M integers, while the i-th number Hi indicates the value of Si.

    T ≤ 15

    0 < N ≤ 50, 0 < M ≤ 100.

    The length of each word is less than 11 and bigger than 0.

    1 ≤ Hi ≤ 100.

    All the words in the input are different.

    All the words just consist of 'a' - 'z'.

    Output

    For each test case, output the string to engrave on a single line.

    If there's more than one possible answer, first output the shortest one. If there are still multiple solutions, output the smallest in lexicographically order.

    The answer may be an empty string.

    Sample Input

    2
    7 2
    love
    ever
    5 5
    5 1
    ab
    5

    Sample Output

    lovever
    abab

    Hint

    Sample 1:

    weight(love) = 5, weight(ever) = 5, so weight(lovever) = 5 + 5 = 10

    Sample 2:

    weight(ab) = 2 * 5 = 10, so weight(abab) = 10

    Source

    样例输入

    2
    7 2
    love
    ever
    5 5
    5 1
    ab
    5

    样例输出

    lovever
    abab

    提示

    Sample 1:

    weight(love) = 5, weight(ever) = 5, so weight(lovever) = 5 + 5 = 10

    Sample 2:

    weight(ab) = 2 * 5 = 10, so weight(abab) = 10


    路过

    雷人

    握手

    鲜花

    鸡蛋

    最新评论

    返回顶部