|
| 1 | +<!--|This file generated by command(leetcode description); DO NOT EDIT. |--> |
| 2 | +<!--+----------------------------------------------------------------------+--> |
| 3 | +<!--|@author openset <openset.wang@gmail.com> |--> |
| 4 | +<!--|@link https://github.com/openset |--> |
| 5 | +<!--|@home https://github.com/openset/leetcode |--> |
| 6 | +<!--+----------------------------------------------------------------------+--> |
| 7 | + |
| 8 | +[< Previous](https://github.com/openset/leetcode/tree/master/problems/number-of-closed-islands "Number of Closed Islands") |
| 9 | + |
| 10 | +Next > |
| 11 | + |
| 12 | +## [1255. Maximum Score Words Formed by Letters (Hard)](https://leetcode.com/problems/maximum-score-words-formed-by-letters "得分最高的单词集合") |
| 13 | + |
| 14 | +<p>Given a list of <code>words</code>, list of single <code>letters</code> (might be repeating) and <code>score</code> of every character.</p> |
| 15 | + |
| 16 | +<p>Return the maximum score of <strong>any</strong> valid set of words formed by using the given letters (<code>words[i]</code> cannot be used two or more times).</p> |
| 17 | + |
| 18 | +<p>It is not necessary to use all characters in <code>letters</code> and each letter can only be used once. Score of letters <code>'a'</code>, <code>'b'</code>, <code>'c'</code>, ... ,<code>'z'</code> is given by <code>score[0]</code>, <code>score[1]</code>, ... , <code>score[25]</code> respectively.</p> |
| 19 | + |
| 20 | +<p> </p> |
| 21 | +<p><strong>Example 1:</strong></p> |
| 22 | + |
| 23 | +<pre> |
| 24 | +<strong>Input:</strong> words = ["dog","cat","dad","good"], letters = ["a","a","c","d","d","d","g","o","o"], score = [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] |
| 25 | +<strong>Output:</strong> 23 |
| 26 | +<strong>Explanation:</strong> |
| 27 | +Score a=1, c=9, d=5, g=3, o=2 |
| 28 | +Given letters, we can form the words "dad" (5+1+5) and "good" (3+2+2+5) with a score of 23. |
| 29 | +Words "dad" and "dog" only get a score of 21.</pre> |
| 30 | + |
| 31 | +<p><strong>Example 2:</strong></p> |
| 32 | + |
| 33 | +<pre> |
| 34 | +<strong>Input:</strong> words = ["xxxz","ax","bx","cx"], letters = ["z","a","b","c","x","x","x"], score = [4,4,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,5,0,10] |
| 35 | +<strong>Output:</strong> 27 |
| 36 | +<strong>Explanation:</strong> |
| 37 | +Score a=4, b=4, c=4, x=5, z=10 |
| 38 | +Given letters, we can form the words "ax" (4+5), "bx" (4+5) and "cx" (4+5) with a score of 27. |
| 39 | +Word "xxxz" only get a score of 25.</pre> |
| 40 | + |
| 41 | +<p><strong>Example 3:</strong></p> |
| 42 | + |
| 43 | +<pre> |
| 44 | +<strong>Input:</strong> words = ["leetcode"], letters = ["l","e","t","c","o","d"], score = [0,0,1,1,1,0,0,0,0,0,0,1,0,0,1,0,0,0,0,1,0,0,0,0,0,0] |
| 45 | +<strong>Output:</strong> 0 |
| 46 | +<strong>Explanation:</strong> |
| 47 | +Letter "e" can only be used once.</pre> |
| 48 | + |
| 49 | +<p> </p> |
| 50 | +<p><strong>Constraints:</strong></p> |
| 51 | + |
| 52 | +<ul> |
| 53 | + <li><code>1 <= words.length <= 14</code></li> |
| 54 | + <li><code>1 <= words[i].length <= 15</code></li> |
| 55 | + <li><code>1 <= letters.length <= 100</code></li> |
| 56 | + <li><code>letters[i].length == 1</code></li> |
| 57 | + <li><code>score.length == 26</code></li> |
| 58 | + <li><code>0 <= score[i] <= 10</code></li> |
| 59 | + <li><code>words[i]</code>, <code>letters[i]</code> contains only lower case English letters.</li> |
| 60 | +</ul> |
| 61 | + |
| 62 | +### Related Topics |
| 63 | + [[Bit Manipulation](https://github.com/openset/leetcode/tree/master/tag/bit-manipulation/README.md)] |
| 64 | + |
| 65 | +### Hints |
| 66 | +<details> |
| 67 | +<summary>Hint 1</summary> |
| 68 | +Note that words.length is small. This means you can iterate over every subset of words (2^N). |
| 69 | +</details> |
0 commit comments