Codeforces_768_D_(概率dp)
2 seconds
256 megabytes
standard input
standard output
Jon Snow is on the lookout for some orbs required to defeat the white walkers. There are k different types of orbs and he needs at least one of each. One orb spawns daily at the base of a Weirwood tree north of the wall. The probability of this orb being of any kind is equal. As the north of wall is full of dangers, he wants to know the minimum number of days he should wait before sending a ranger to collect the orbs such that the probability of him getting at least one of each kind of orb is at least , where ε < 10 - 7.
To better prepare himself, he wants to know the answer for q different values of pi. Since he is busy designing the battle strategy with Sam, he asks you for your help.
First line consists of two space separated integers k, q (1 ≤ k, q ≤ 1000) — number of different kinds of orbs and number of queries respectively.
Each of the next q lines contain a single integer pi (1 ≤ pi ≤ 1000) — i-th query.
Output q lines. On i-th of them output single integer — answer for i-th query.
1 1
1
1
2 2
1
2
2
2
题意:有k种球,每天可得到一个球,其种类是任意一种,问每种球至少有一个的概率至少为 (p<1000)需要几天。
自己只想到用概率去算,但是也不知对不对,几乎没有思路,于是看了官方题解。
思路:dp[i][j]:第i天有j种的概率。那么可以有dp[i][j]=dp[i-1][j]*(j/k)+dp[i-1][j-1]*(k-j+1)/k;
看了题解觉得很容易,但是自己却想不到啊。。。。。。。
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
#define N 10005
double dp[N][]; int main()
{
int k,q;
scanf("%d%d",&k,&q);
dp[][]=;
for(int i=; i<N; i++)
for(int j=; j<=k; j++)
dp[i][j]=dp[i-][j]*((double)j/k)+dp[i-][j-]*((double)(k-j+)/k);
while(q--)
{
double p;
scanf("%lf",&p);
int i;
for(i=; i<N; i++)
if(dp[i][k]>=(p/))
break;
printf("%d\n",i);
}
return ;
}
Codeforces_768_D_(概率dp)的更多相关文章
- Codeforces 28C [概率DP]
/* 大连热身D题 题意: 有n个人,m个浴室每个浴室有ai个喷头,每个人等概率得选择一个浴室. 每个浴室的人都在喷头前边排队,而且每个浴室内保证大家都尽可能均匀得在喷头后边排队. 求所有浴室中最长队 ...
- HDU 4405 Aeroplane chess (概率DP)
题意:你从0开始,要跳到 n 这个位置,如果当前位置是一个飞行点,那么可以跳过去,要不然就只能掷骰子,问你要掷的次数数学期望,到达或者超过n. 析:概率DP,dp[i] 表示从 i 这个位置到达 n ...
- POJ 2096 Collecting Bugs (概率DP)
题意:给定 n 类bug,和 s 个子系统,每天可以找出一个bug,求找出 n 类型的bug,并且 s 个都至少有一个的期望是多少. 析:应该是一个很简单的概率DP,dp[i][j] 表示已经从 j ...
- POJ 2151 Check the difficulty of problems (概率DP)
题意:ACM比赛中,共M道题,T个队,pij表示第i队解出第j题的概率 ,求每队至少解出一题且冠军队至少解出N道题的概率. 析:概率DP,dp[i][j][k] 表示第 i 个队伍,前 j 个题,解出 ...
- 概率DP light oj 1030
t组数据 n块黄金 到这里就捡起来 出发点1 到n结束 点+位置>n 重掷一次 dp[i] 代表到这里的概率 dp[i]=(dp[i-1]+dp[i-2]... )/6 如果满6个的话 否则 ...
- hdu 4050 2011北京赛区网络赛K 概率dp ***
题目:给出1-n连续的方格,从0开始,每一个格子有4个状态,左右脚交替,向右跳,而且每一步的步长必须在给定的区间之内.当跳出n个格子或者没有格子可以跳的时候就结束了,求出游戏的期望步数 0:表示不能到 ...
- [转]概率DP总结 by kuangbin
概率类题目一直比较弱,准备把kuangbin大师傅总结的这篇题刷一下! 我把下面的代码换成了自己的代码! 原文地址:http://www.cnblogs.com/kuangbin/archive/20 ...
- SGU 422 Fast Typing(概率DP)
题目大意 某人在打字机上打一个字符串,给出了他打每个字符出错的概率 q[i]. 打一个字符需要单位1的时间,删除一个字符也需要单位1的时间.在任意时刻,他可以花 t 的时间检查整个打出来的字符串,并且 ...
- HDU 4050 wolf5x(动态规划-概率DP)
wolf5x Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 32768/32768 K (Java/Others) Total Sub ...
随机推荐
- Android.mk文件解析
一.一个简单的Android.mk文件例如以下: LOCAL_PATH := $(call my-dir) include $(CLEAR_VARS) LOCAL_MODULE := nativ ...
- 关于Windows 8使用WMP播放音乐时WUDFHost跑CPU和硬盘的问题解决
Windows 8使用Windows Media Player播放音乐的时候.事实上有一个这种情况,WMP和某个什么名字看起来非常屌的进程跑CPU非常高,这个跑非常高视你插入的SD卡内的文件数或者移动 ...
- ubuntu下apache+mysql+php+mysql等之webserver搭建
相信非常多人跟我一样,想搭建一个自己的webserver.网上资料非常多.可是因为版本号的区别,总是存在依照一个教程来做无法全然实现的问题.近期我也折腾了好几天,google不能用,仅仅能百度,真想说 ...
- [翻译角]Headline English: A Captain Should Be Pitch Perfect at a Multitude of Skills (ESLPOD Blog)
以下转自www.eslpod.com,翻译为本人添加.其余版权均归原网站所有. ESLPOD是一个英语学习网站,我最初知道这个网站,是因为“奶爸”<把你的英语用起来>(电子版3元)一书的推 ...
- socketserver模块三次登陆验证,身份验证
帅爆太阳的男人 1,socketserver是解决TCP服务器和多个客户端进行通信 服务器: import socketserver class MySocket(socketserver,BaseR ...
- 【uoj35】后缀排序
后缀数组模板题 #include<algorithm> #include<cstdlib> #include<cstring> #include<cstdio ...
- ubuntu 截图工具 Shutter,设置快捷键 Ctrl+Alt+A
系统设置 键盘 快捷键 自定义快捷键
- Tarjan求桥
传送门(poj3177) 这道题是Tarjan求桥的模板题.大意是要求在原图上加上数量最少的边,使得整张图成为一个边双联通分量. 具体的做法是,先在图中求出所有的桥,之后把边双联通分量缩成点,这样的话 ...
- 8 Range 对象
8.1 引用Range 引用Range的主要方法: Application.ActiveCell Application.Range Application.Selection Worksheet.C ...
- ubuntu 16.04 Eclipse 图标显示为 ?(已解决)
这个问题挺好解决: sudo gedit /usr/share/applications/eclipse.desktop在这个文件中将Icon=/home/soyo/eclipse/icon.xpm, ...