아직 만들고 있는 페이지입니다.

이 페이지는 아직 만드는 중입니다. 보이는 내용은 바뀔 수 있습니다.

Cow Word Games

면접 대비

시간 제한1초메모리 제한1024 MB

요약
점수 값이 있는 N개의 글자 타일과 M개 단어 사전이 주어질 때, 타일의 부분집합으로 만들 수 있는 사전 단어의 최대 점수를 구하고, 없으면 -1을 출력한다.
난이도

보통10점 중 4점

유형
해시맵, 문자열, 배열, 완전 탐색
정답자
아직 제출이 없습니다

문제

Tired of being teased by the other farm animals for their poor vocabulary, Farmer John's cows have stolen a word game from FJ's house to use for practice. In this particular word game, each cow receives a set of N (1 ≤ N ≤ 100) not necessarily unique uppercase letters (for example: 'V', 'B', 'O', 'E', 'I', 'N', 'O'). Each letter has a certain specified point value, and each cow's goal is to form a valid word using a subset of her letters worth the maximum number of points. For example, if every letter is worth 1 point, the maximum number of points one can receive from the letters above is 6, using the word 'BOVINE'.

The cows have also managed to steal a dictionary containing M (1 ≤ M ≤ 10,000) words from FJ's house, so they can check whether or not certain words are valid. Please help his cows compute the best possible words they can form based on the letters they receive.

입력

  • Line 1: Two space-separated integers, N and M (1 ≤ M ≤ 10000).
  • Lines 2..27: Each of these 26 lines contains a positive integer giving the number of points for a letter of the alphabet. The first of these lines corresponds to 'A'; the last corresponds to 'Z'.
  • Lines 28..N+27: These N lines contain the letters received by a cow playing the game. Each line contains a single uppercase letter.
  • Lines N+28..N+M+27: These M lines each contain a word from the dictionary. Each word consists of at most N uppercase letters.

출력

  • Line 1: A single integer, specifying the maximum number of points we can receive. If no valid words in the dictionary can be formed, output -1.

힌트

All letters are worth 1 point except 'C', which is worth 10 points. We receive the letters 'D', 'C', 'O', 'R', and 'W'.

The word 'COW' is worth 12 points, and we can form it using a subset of the letters in our input.

예제1

  1. 예제 1

    입력
    5 4
    1
    1
    10
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    1
    D
    C
    O
    R
    W
    WORD
    COW
    COURT
    ROW
    
    예상 출력
    12