求解概率的坑题

部署运行你感兴趣的模型镜像
D - Problem D
Time Limit:1000MS     Memory Limit:131072KB     64bit IO Format:%lld & %llu

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

绝对是被坑了,一直都没有想到通过递推的的方式来求解,结果计算越来越复杂,后来就不能忍了,受不了,以后坚决不能犯这样的低级错误……

转载于:https://www.cnblogs.com/tianxia2s/p/3911904.html

您可能感兴趣的与本文相关的镜像

LobeChat

LobeChat

AI应用

LobeChat 是一个开源、高性能的聊天机器人框架。支持语音合成、多模态和可扩展插件系统。支持一键式免费部署私人ChatGPT/LLM 网络应用程序。

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值