Datasets:

Modalities:
Image
Text
Formats:
parquet
Size:
< 1K
Tags:
code
Libraries:
Datasets
pandas
License:
File size: 1,988 Bytes
761e24d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
<p>
This morning you woke up with an uncontrollable urge to send a text message made up of
<strong>K</strong> distinct words. But, can you believe it? 
Your new phone just crashed and all of the words are missing from its dictionary!
You used to have <strong>N</strong> words in there, and you certainly don't have time to add all
of them back right now.
</p>

<p>
Your plan is to just choose <strong>K</strong> of the <strong>N</strong> possible words, add them to your phone's dictionary, and then text each of them. To text a certain word, you must either type the word itself, or any nonempty prefix of it which is not a prefix of any other word in the dictionary.
</p>

<p>
What's the minimum number of letters you must type to send your message of <strong>K</strong> words?
</p>


<h3>Input</h3>

<p>
Input begins with an integer <strong>T</strong>, the number of test cases.
For each test case, there is first a line containing the space-separated integers 
<strong>N</strong> and <strong>K</strong>.
Then, <strong>N</strong> lines follow, each containing a word that used to be in your phone's dictionary.
</p>


<h3>Output</h3>

<p>
For the <strong>i</strong>th test case, print a line containing "Case #<strong>i</strong>: " followed by
the minimum number of characters you need to type to send your text message.
</p>


<h3>Constraints</h3>
<p>
1 &le; <strong>T</strong> &le; 20 <br />
2 &le; <strong>N</strong> &le; 4,000 <br />
1 &le; <strong>K</strong> &le; min(<strong>N</strong>-1, 100) <br />
</p>

<p>
The <strong>N</strong> words will have a total length of no more than 20,000 characters. <br />
The words are made up of only lower-case alphabetic characters. <br />
The words are pairwise distinct. <br />
</p>


<h3>Explanation of Sample</h3>
<p>
In the first case, one option is to choose the words "tin", "tinny", "gigantic", and "tilts". You can then text these words by typing "tin", "tinn", "g", and "til", respectively, for a total of 3+4+1+3=11 letters.
</p>