久违的 first time ac!
USER: sendong li [lisendo1]LANG: C++ Compiling... Compile: OK Executing... Test 1: TEST OK [0.043 secs, 4132 KB] Test 2: TEST OK [0.043 secs, 4132 KB] Test 3: TEST OK [0.054 secs, 4132 KB] Test 4: TEST OK [0.054 secs, 4132 KB] Test 5: TEST OK [0.054 secs, 4132 KB] Test 6: TEST OK [0.043 secs, 4132 KB] Test 7: TEST OK [0.043 secs, 4132 KB] Test 8: TEST OK [0.043 secs, 4132 KB] Test 9: TEST OK [0.043 secs, 4132 KB] Test 10: TEST OK [0.043 secs, 4132 KB] Test 11: TEST OK [0.054 secs, 4132 KB] Test 12: TEST OK [0.054 secs, 4132 KB] All tests OK.YOUR PROGRAM ('lgame') WORKED FIRST TIME! That's fantastic -- and a rare thing. Please accept these special automated congratulations.
Here are the test data inputs:
------- test 1 ---- jicuzza ------- test 2 ---- cuqak ------- test 3 ---- pofax ------- test 4 ---- rammoxy ------- test 5 ---- culatu ------- test 6 ---- gvutvac ------- test 7 ---- bhruthr ------- test 8 ---- wagje ------- test 9 ---- thryst ------- test 10 ---- fnupfig ------- test 11 ---- bobdead ------- test 12 ---- abcdefgKeep up the good work!
Thanks for your submission!
Letter GameIOI 1995 Figure 1: Each of the 26 lowercase letters and its valueLetter games are popular at home and on television. In one version of the game, every letter has a value, and you collect letters to form one or more words giving the highest possible score. Unless you have `a way with words', you will try all the words you know, sometimes looking up the spelling, and then compute the scores. Obviously, this can be done more accurately by computer.
Given the values in Figure 1, a list of words, and the letters collected: find the highest scoring words or pairs of words that can be formed.
prmgroa
profile program prom rag ram rom .
On the first line, your program should write the highest possible score, and on each of the following lines, all the words and/or word pairs from filelgame.dict with this score. Sort the output alphabetically by first word, and if tied, by second word. A letter must not occur more often in an output line than in the input line. Use the letter values given in Figure 1.
When a combination of two words can be formed with the given letters, the words should be printed on the same line separated by a space. The two words should be in alphabetical order; for example, do not write `rag prom', only write `prom rag'. A pair in an output line may consist of two identical words.
This output uses the tiny dictionary above, not the lgame.dict dictionary.
24 program prom rag
分析: 该题目的字典文件有40000行,乍一看以为 n^2的穷举算法会超时。但仔细一想,input中只有最多7位数字,因此排列组合最多情况也就只有 7! 种情况 枚举是完全可以通过的!
代码如下: