【动态规划,小数据集打表(误)】
题目翻译
这个游戏是用3N张牌来进行的,这3张相同的牌标为1,3张相同的牌标为2,以此类推,直到3张相同的牌标为N。
这些牌被洗牌(这样所有可能的牌序出现的概率都是相等的),然后面朝下放在桌子上,所以牌面是未知的。
游戏的每一轮进行如下:
选择其中一张卡片,翻过来显示它的号码。
选择第二张卡片并翻过来显示其号码。如果该数字不等于第一张卡片上显示的数字,则回合结束,您不能翻转第三张卡片。
否则:
选择第三张卡片,翻过来显示它的号码。如果该数字不等于第二张卡片上显示的数字,则回合结束。否则,你已经找到一个“三对”,你可以从游戏中移除这三张牌,然后回合结束。
回合结束后,如果桌上没有牌了,你就赢了。
否则,在开始下一轮之前,你必须把之前翻开的牌翻回去,以隐藏它们的号码,但你有惊人的记忆力,你可以记住它们在哪里。
请注意,即使您已经知道卡片的号码,也可以选择翻转该卡片。
另外,即使你知道某个“三对”中所有卡片的位置,你也必须在同一回合中翻转这三张卡片才能移除它。
你希望尽快赢得比赛,所以你使用聪明的策略,使结束比赛所需的预期回合数最小化。
该预期的回合数是多少?(误差小于10-6)
Problem
The game of Tricky Trios is played using a deck of 3N cards consisting of three identical cards labeled 1, three identical cards labeled 2, and so on, up to three identical cards labeled N. The cards are shuffled (such that all possible card orderings have an equal probability of appearing), and then dealt out onto a table, face down, so that all the numbers are hidden.
Each round of the game proceeds as follows:
Choose one of the cards and flip it over to reveal its number.
Choose a second card and flip it over to reveal its number. If that number is not equal to the revealed number on the first card, the round is over and you may not flip a third card. Otherwise:
Choose a third card and flip it over to reveal its number. If that number is not equal to the revealed number on the second card, the round is over. Otherwise, you have found a trio, and you can remove all three cards from the game; then the round is over.
Once the round is over, if there are no more cards remaining, you have won the game. Otherwise, before beginning the next round, you must flip all revealed cards back over to hide their numbers, but you have an amazing memory and you can remember where they are for the rest of the game.
Note that you may choose to flip a card even if you already know its number. Also, even if you know the locations of all of the cards in a trio, you must actually flip all three cards in the trio on the same round in order to remove it.
You would like to win as quickly as possible, so you will use a strategy that minimizes the expected number of rounds needed to end the game. What is that expected number of rounds?
Input
The first line of the input gives the number of test cases, T; T test cases follow. Each consists of one line with an integer N, as described above.
Output
For each test case, output one line containing Case #x: y, where x is the test case number (starting from 1) and y is a rational: the minimal expected number of rounds needed to end the game, as described above. y will be considered correct if it is within an absolute or relative error of 10-6 of the correct answer. See the FAQ for an explanation of what that means, and what formats of real numbers we accept.
Limits
Time limit: 20 seconds per test set.
Memory limit: 1GB.
Small dataset (Test set 1 - Visible)
1 ≤ T ≤ 5.
1 ≤ N ≤ 5.
Large dataset (Test set 2 - Hidden)
1 ≤ T ≤ 100.
1 ≤ N ≤ 100.
Sample
Input
3
1
2
5
Output
Case #1: 1.000000
Case #2: 3.400000
Case #3: 9.842024
In Sample Case #1, all three cards have the same number, so flipping them over in any order will end the game in one round.
In Sample Case #2:
If the first two cards we flip over are different, our round ends and we cannot flip over a third card. Then, we can use the next round to flip over two more of the unknown cards.
If they match, then we already know where the remaining third card is, and then we can use one more round to flip over the remaining trio, taking three rounds total. The chances of this scenario are 3/5 × 1/3 = 1/5.
Otherwise, our second round ends, but once we have flipped over another unknown card on the third round, we know how to finish building both trios, taking four rounds total. The chances of this scenario are 3/5 × 2/3 = 2/5.
If the first two cards we flip over are the same, we leave the details as an exercise for the solver.
The answer is 3 × 1/5 + 4 × 2/5 + … = 17/5.