#P3864. [USACO1.2] 命名那个数字 Name That Number

    ID: 2742 远端评测题 1000ms 225MiB 尝试: 0 已通过: 0 难度: 5 上传者: 标签>模拟字符串搜索USACO枚举,暴力深度优先搜索,DFS

[USACO1.2] 命名那个数字 Name That Number

Description

Among dairy farmers in Wisconsin, it is customary for the accounting department to brand cows with consecutive numbers. The cows themselves do not find this system convenient; they prefer to call their companions by their favorite names rather than with phrases like "C'mon, #4364, be friendly." Please write a program to help the poor cowhands translate a cow's brand number into a possible name. Since cows now all have cell phones, you can convert digits to letters according to the table below.

Digit Letters
22 A,B,C
33 D,E,F
44 G,H,I
55 J,K,L
66 M,N,O
77 P,R,S
88 T,U,V
99 W,X,Y

Note that the letters Q and Z are not present.

The set of acceptable cow names is stored in a file called "dict.txt", which contains a sequence of fewer than 50005000 (specifically, 46174617) acceptable names. All names are uppercase and already sorted in lexicographical order. Read the cow's number and return those names that can be translated from the number and appear in the dictionary. For example, among the 8181 names generated by the number 47344734, only "GREG" is valid (i.e., present in the dictionary).

Write a program to print all valid names for the given number. If there are none, output NONE.

Input Format

The first line contains a number of length 11 to 1212.

The following lines (until EOF), one per line, each contain a string representing an acceptable name.

Output Format

Output a deduplicated list of valid names in lexicographical order, one name per line. If there are no valid names, output NONE.

4734
NMSL
GREG
LSDC
....(太多了不写了)
GREG

Hint

All combinations producible from 47344734 are as follows:

GPDG GPDH GPDI GPEG GPEH GPEI GPFG GPFH GPFI GRDG GRDH GRDI GREG GREH GREI GRFG GRFH GRFI GSDG GSDH GSDI GSEG GSEH GSEI GSFG GSFH GSFI HPDG HPDH HPDI HPEG HPEH HPEI HPFG HPFH HPFI HRDG HRDH HRDI HREG HREH HREI HRFG HRFH HRFI HSDG HSDH HSDI HSEG HSEH HSEI HSFG HSFH HSFI IPDG IPDH IPDI IPEG IPEH IPEI IPFG IPFH IPFI IRDG IRDH IRDI IREG IREH IREI IRFG IRFH IRFI ISDG ISDH ISDI ISEG ISEH ISEI ISFG ISFH ISFI

Translated by ChatGPT 5