Yinyangshi is a famous RPG game on mobile phones.
Kim enjoys collecting cards in this game. Suppose there are n kinds of cards. If you want to get a new card, you need to pay W coins to draw a card. Each time you can only draw one card, all the cards appear randomly with same probability 1/n. Kim can get 1 coin each day. Suppose Kim has 0 coin and no cards on day 0. Every W days, Kim can draw a card with W coins. In this problem ,we define W=(n-1)!.
Now Kim wants to know the expected days he can collect all the n kinds of cards.
The first line an integer T(1 ≤ T ≤ 10). There are T test cases.
The next T lines, each line an integer n. (1≤n≤3000)
For each n, output the expected days to collect all the n kinds of cards, rounded to one decimal place.
4 1 2 5 9Sample Output
1.0 3.0 274.0 1026576.0
题意:抽n张不同的牌,每一次只能抽一张牌,抽到每张牌的概率都是相等的,都是1/n。每隔W天抽一次,W=(n-1)!。问预期多少天能抽完。
解题思路:
老铁kangzzz求期望真的是无敌666了
求出期望的次数然后乘上W即为结果。
在解题上有个难点就是怎么求期望,在求出公式后的难点就是怎么求W,W是一个3000的阶乘,用java可以实现,C语言先放放。。
举例:
n==2时,
抽第一张不同的牌只需要1次
抽第二张不同的牌的概率是1/2,预期的次数是1/(1/2)=2 次
所以总的预期天数是(1+2)*W==3天
n==3时,
抽第一张不同的牌只需要1次,
抽剩余两张不同的牌的概率是2/3,那么预期的次数就是1/(2/3)==3次,平均抽每张牌就需要3/2次
再抽剩余的一张牌需要的次数就是3/1次
所以公式就是(n/n+n/(n-1)+n/(n/2)+...+n/1)*(n-1)!