码迷,mamicode.com
首页 > 其他好文 > 详细

CSU 1290

时间:2014-08-14 23:48:26      阅读:211      评论:0      收藏:0      [点我收藏+]

标签:des   style   blog   http   color   os   io   for   

 

1290: Random Integers

Time Limit: 1 Sec  Memory Limit: 128 MB
Submit: 72  Solved: 45
[Submit][Status][Web Board]

Description

We choose an integer K (K > 0). Then we generate N (N > 0) integers one by one randomly, each of them is in range [0, K - 1], and the appearing probabilities of each interger is the same,they are all 1/K.
Can you tell us the expectation of the number of distinct integers in that N integers?

Input

There is an integer T (1 <= T <= 200) in the first line, means there are T test cases in total.
For each test case, there are two integers K (1 <= K <= 1000), N (1 <= N <= 1000), which have the same meaning as above.

Output

For each test case, you should print the result in one line. You should keep the first 5 digits after the decimal point.

Sample Input

5
1 1
2 2
3 2
3 4
5 3

Sample Output

1.00000
1.50000
1.66667
2.40741
2.44000

HINT

 

Source

Multi-University Contest Fina

 

没看出这是DP

看出来也不一定想得到

 1 #include <cstdio>
 2 double dp[1005];
 3 int main()
 4 {
 5     int t;
 6     scanf("%d", &t);
 7     while (t--)
 8      {
 9         int m,n;
10         scanf("%d %d", &m, &n);
11         dp[1] = 1.0;
12         for (int i = 2; i <= n; ++i)
13             dp[i] = dp[i-1] + (m/1.0 - dp[i-1])/1.0/m;
14         printf("%.5f\n", dp[n]);
15     }
16     return 0;
17 }

 

CSU 1290,布布扣,bubuko.com

CSU 1290

标签:des   style   blog   http   color   os   io   for   

原文地址:http://www.cnblogs.com/Run-dream/p/3913553.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!