Max Score

hard
1. You are given a list of words, a list of alphabets(might be repeating) and score of every alphabet 
     from a to z.
2. You have to find the maximum score of any valid set of words formed by using the given 
     alphabets.
3. A word can not be used more than one time.
4. Each alphabet can be used only once. 
5. It is not necessary to use all the given alphabets.

Note -> Check out the question video and write the recursive code as it is intended without 
               changing signature. The judge can't force you but intends you to teach a concept.

Input Format

A number N representing number of words N space separated strings A number M representing number of alphabets(might be repeating) M space separated characters 26 numbers representing score of unique alphabets from a to z.

Output Format

Check the sample ouput and question video.

Constraints

1 <= N <= 14
1 <= length of word <= 15
1 <= M <= 100
1 <= Value of score <= 10

Notice

Try First, Check Solution later

1. You should first read the question and watch the question video.
2. Think of a solution approach, then try and submit the question on editor tab.
3. We strongly advise you to watch the solution video for prescribed approach.

Example

Input
4
dog cat dad good
9
a b c d d d g o o
1 0 9 5 0 0 3 0 0 0 0 0 0 0 2 0 0 0 0 0 0 0 0 0 0 0
Output
23
Previous
Josephus Problem
Next
N Queens - Branch And Bound

Related Questions