#P4407. [JSOI2009] 电子字典
[JSOI2009] 电子字典
Description
When looking up a word in an English dictionary, people may not know the exact spelling and only know an incorrect approximate spelling. This can be frustrating and waste a lot of time. An electronic dictionary with fuzzy search can help: the user enters a string, and the dictionary returns a few words with the minimum edit distance to that string for the user to choose from.
The edit distance between string and string is defined as the minimum number of the following editing operations needed to transform into or into :
- Delete a letter at some position in the string.
- Insert a letter at some position in the string.
- Replace the letter at some position in the string with another letter.
The JSOI team is developing an electronic dictionary. You need to help implement a counting module for the fuzzy search function: for a query string, if it is a word, return ; if it is not a word, return how many words in the dictionary have edit distance from it.
Input Format
The first line contains two positive integers and .
The next lines each contain one string; the -th line is the word , with length from to .
Then the next lines each contain one string; the -th line is the query string . The length of each query string is from to . Each of and consists of lowercase letters. There are no extra spaces in the input.
Output Format
Output lines. The -th line contains an integer :
- means is a word in the dictionary.
- Otherwise, is the number of dictionary words whose edit distance from is .
4 3
abcd
abcde
aabc
abced
abcd
abc
abcdd
-1
2
3
Hint
Sample explanation:
abcdappears in the word list.- The edit distance between
abcand each ofabcdandaabcis . - The edit distance between
abcddand each ofabcd,abcde, andabcedis .
Constraints and Notes:
- All words are distinct, but query strings may repeat.
- For of the constraints, .
- For of the constraints, .
Translated by ChatGPT 5
京公网安备 11011102002149号