BUPT Summer Journey #test11 C
来源:互联网 发布:淘宝入店来源其他来源 编辑:程序博客网 时间:2024/05/14 23:49
C. 小妹妹采蘑菇 2014新生暑假个人排位赛11
时间限制 1000 ms 内存限制 65536 KB
题目描述
在广茂的大森林里居住着一位可爱的小妹妹,以及一位怪叔叔。这天,怪叔叔让小妹妹为他做一锅蘑菇汤,可怜的小妹妹只好出门采集蘑菇。怪叔叔知道,森林里一共有n种不同的蘑菇,所以他提出了一个变态的要求,小妹妹必须为他做一锅包含所有n种蘑菇的汤。也就是说,小妹妹至少要采集齐所有的n种蘑菇。她想知道,平均要采多少朵蘑菇能满足怪叔叔的要求,注意,她每次所采的蘑菇是等概率的。
输入格式
多组case,case<=100。每组case一行一个数n,1<=n<=100。输入以EOF结束。
输出格式
每组case输出一行答案,保留六位小数。
输入样例
12
输出样例
1.0000003.000000
思路:将采到i种不同蘑菇的期望设为dp[i],则dp[i+1]=(n-i)/n*(dp[i]+1)+i*(n-i)/n^2(dp[i]+2)+...化简得,dp[i+1]=dp[i]+(n-i)/n,一轮扫描即可。
代码:
#include<iostream>#include<cstdio>#include<cstdlib>#include<cstring>#include<cmath>#define maxn 200using namespace std;double dp[maxn];int main(){ int n; while(scanf("%d",&n)==1) { dp[1]=1.0; for(int i=2;i<=n;i++)dp[i]=dp[i-1]+(double)n/(double)(n-i+1); printf("%.6lf\n",dp[n]); } return 0;}
0 0
- BUPT Summer Journey #test11 C
- BUPT Summer Journey #test11 A
- BUPT Summer Journey #test11 B
- BUPT Summer Journey #test11 E
- BUPT Summer Journey #test1 C
- BUPT Summer Journey #test2 C
- BUPT Summer Journey #test3 C
- BUPT Summer Journey #test4 C
- BUPT Summer Journey #test5 C
- BUPT Summer Journey #test6 C
- BUPT Summer Journey #test7 C
- BUPT Summer Journey #test8 C
- BUPT Summer Journey #test9 C
- BUPT Summer Journey #test1 A
- BUPT Summer Journey #test1 B
- BUPT Summer Journey #test1 D
- BUPT Summer Journey #test1 E
- BUPT Summer Journey #test2 A
- 将10位和13位时间戳转换为时间
- BUPT Summer Journey #test11 B
- go语言第三天
- 【Oracle强化】②第二章 编写控制结构
- [ACM] hdu 3555 Bomb (数位DP,统计1-N中含有“49”的总数)
- BUPT Summer Journey #test11 C
- C++ map键值对用
- Linux命令:ls
- 居者有其屋
- 求和问题总结
- SOA与ESB介绍
- zkpython demo
- 空指针的判断与思考
- cocos2d-x 3.0 制作我的微信飞机大战