D. Jon and Orbs
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

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.

Input

First line consists of two space separated integers kq (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

Output q lines. On i-th of them output single integer — answer for i-th query.

Examples
input
1 1
1
output
1
input
2 2
1
2
output
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)的更多相关文章

  1. Codeforces 28C [概率DP]

    /* 大连热身D题 题意: 有n个人,m个浴室每个浴室有ai个喷头,每个人等概率得选择一个浴室. 每个浴室的人都在喷头前边排队,而且每个浴室内保证大家都尽可能均匀得在喷头后边排队. 求所有浴室中最长队 ...

  2. HDU 4405 Aeroplane chess (概率DP)

    题意:你从0开始,要跳到 n 这个位置,如果当前位置是一个飞行点,那么可以跳过去,要不然就只能掷骰子,问你要掷的次数数学期望,到达或者超过n. 析:概率DP,dp[i] 表示从 i  这个位置到达 n ...

  3. POJ 2096 Collecting Bugs (概率DP)

    题意:给定 n 类bug,和 s 个子系统,每天可以找出一个bug,求找出 n 类型的bug,并且 s 个都至少有一个的期望是多少. 析:应该是一个很简单的概率DP,dp[i][j] 表示已经从 j ...

  4. POJ 2151 Check the difficulty of problems (概率DP)

    题意:ACM比赛中,共M道题,T个队,pij表示第i队解出第j题的概率 ,求每队至少解出一题且冠军队至少解出N道题的概率. 析:概率DP,dp[i][j][k] 表示第 i 个队伍,前 j 个题,解出 ...

  5. 概率DP light oj 1030

    t组数据 n块黄金 到这里就捡起来 出发点1 到n结束  点+位置>n 重掷一次 dp[i] 代表到这里的概率 dp[i]=(dp[i-1]+dp[i-2]... )/6  如果满6个的话 否则 ...

  6. hdu 4050 2011北京赛区网络赛K 概率dp ***

    题目:给出1-n连续的方格,从0开始,每一个格子有4个状态,左右脚交替,向右跳,而且每一步的步长必须在给定的区间之内.当跳出n个格子或者没有格子可以跳的时候就结束了,求出游戏的期望步数 0:表示不能到 ...

  7. [转]概率DP总结 by kuangbin

    概率类题目一直比较弱,准备把kuangbin大师傅总结的这篇题刷一下! 我把下面的代码换成了自己的代码! 原文地址:http://www.cnblogs.com/kuangbin/archive/20 ...

  8. SGU 422 Fast Typing(概率DP)

    题目大意 某人在打字机上打一个字符串,给出了他打每个字符出错的概率 q[i]. 打一个字符需要单位1的时间,删除一个字符也需要单位1的时间.在任意时刻,他可以花 t 的时间检查整个打出来的字符串,并且 ...

  9. HDU 4050 wolf5x(动态规划-概率DP)

    wolf5x Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

随机推荐

  1. Linux下C编程的学习_1

    0x0:为什么写这个系列的文章 博客原本的定位是安卓游戏的破解,可是为什么写这系列的文章呢? 由于在破解过程中,我们是无法避免来敲代码的,恢复算法,模拟算法,游戏中对数据的解密.游戏中对保存在clie ...

  2. c#实现播放器的集中方式

    http://www.cnblogs.com/iskyoole/archive/2012/03/25/2417181.html(原文链接地址) 一.使用vs自带的windows media play控 ...

  3. ZOJ Design the city LCA转RMQ

    Design the city Time Limit: 1 Second      Memory Limit: 32768 KB Cerror is the mayor of city HangZho ...

  4. 安装Node.js 以及命令行使用

    安装 官方的安装包 安装完成之后,会自动添加到环境变量中 通过visual studio安装 命令行 查看版本 PS C:\Users\clu\Desktop> node --version v ...

  5. POJ 1060:Modular multiplication of polynomials

    Modular multiplication of polynomials Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 4 ...

  6. CF 908 D New Year and Arbitrary Arrangement —— 期望DP

    题目:http://codeforces.com/contest/908/problem/D 首先,设 f[i][j] 表示有 i 个 a,j 个 ab 组合的期望,A = pa / (pa + pb ...

  7. MSD6A628开发资料与技术支持

    MSD6A628VX/VXM是mstar推出的低成本安卓智能网络电视方案,628分两个版本,一个是内置512MB内存,一个是外挂1G内存, 安卓4.4系统,4核A7处理器,Mali450MP2 GPU ...

  8. Spark 分布式环境---slave节点无法启动(已解决)

    soyo@soyo-VPCCB3S1C:~$ start-slaves.sh soyo-slave01: starting org.apache.spark.deploy.worker.Worker, ...

  9. Spark GraphX 属性图操作

    package Spark_GraphX import org.apache.spark.graphx._ import org.apache.spark.rdd.RDD import org.apa ...

  10. EasyUI Datagrid 分页显示(客户端)

    转自:https://blog.csdn.net/metal1/article/details/17536185 EasyUI Datagrid 分页显示(客户端) By ZYZ 在使用JQuery ...