1743. Scrabble

单点时限: 2.0 sec

内存限制: 256 MB

The game of Scrabble is played with tiles. A tile either has a single letter written on it, or it is blank. In the latter case, the tile may be used to represent a letter of your choice. On your turn, you arrange the tiles to form a word. Each tile may be used at most once, but not all tiles need to be used. Given several Scrabble tiles and a dictionary, determine how many words in the dictionary can be formed using the given Scrabble tiles.

输入格式

The input test file will contain multiple test cases. In each test case, the first line contains a positive integer n ≤ 1000 indicating the number of words in the dictionary. The following n lines each contain a single string with between 1 and 7 uppercase letters, representing a word in the dictionary. No word will appear in the dictionary twice. The next line contains a single string giving the tiles you have available. It will contain only capital letters, representing tiles with that letter on it, and underscores, representing blank tiles. The string will contain between 1 and 7 characters, possibly including duplicate tiles. The end-of-file is marked by a test case with n = 0 and should not be processed.

输出格式

For each test case, write a single line with the number of dictionary words that can be spelled with the given Scrabble tiles.

样例

Input
5
PROGRAM
CONTEST
PIZZA
ZA
PITA
_PIZA
3
BANANAS
CARROTS
FIGS
A__AA__
Output
3
2
Hint
In the first test case, PIZZA, ZA and PITA can be spelled as PIZ_A, ZA and PI_A. There are not enough letters to spell PROGRAM or CONTEST. In the second test case, BANANAS and FIGS can be spelled as _A_A_A_ and ____. On the other hand, CARROTS would require 6 blanks in addition to the A.

3 人解决,5 人已尝试。

3 份提交通过,共有 6 份提交。

8.1 EMB 奖励。

创建: 16 年,6 月前.

修改: 6 年,8 月前.

最后提交: 3 年,5 月前.

来源: Stanford Local 2005

题目标签