Dice (III) 概率dp
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>
using namespace std;
int t,n;
double dp[100010];
int main()
{
scanf("%d",&t);
int cas=1;
while(t--)
{
scanf("%d",&n);
dp[n]=0;
for(int i=n-1;i>=0;i--)
dp[i]=dp[i+1]+(double)(n)/(n-i);
printf("Case %d: %.8lf\n",cas++,dp[0]);
}
}
这一题期初我怎么也没理解这递推方程。后来想通一个说法。
dp[i]表示您还差i面没扔出来时你扔的次数。
dp[i]=i/n*dp[i]+(n-i)/n*dp[i+1]+1;
dp[i]=dp[i+1]+(double)(n)/(n-i);
现在让我来分析一下:
为什么i/n*dp[i]+(n-i)/n*dp[i+1]呢,我觉得是(n-i)/n*(dp[i]+1)+(i+1)/n*(dp[i+1]+1)
其实这个要反着考虑一下。就是n个你选i个里面的那么造成了dp[i],不然还是dp[i+1].。这个从后往前。
Dice (III) 概率dp的更多相关文章
- LightOJ 1248 Dice (III) (期望DP / 几何分布)
题目链接:LightOJ - 1248 Description Given a dice with n sides, you have to find the expected number of t ...
- dice 概率论 概率DP
题目链接: http://acm.hdu.edu.cn/contests/contest_showproblem.php?pid=1010&cid=459 找出公式,公式有实际意义,某种情形当 ...
- LightOJ 1248 Dice (III) 概率
Description Given a dice with n sides, you have to find the expected number of times you have to thr ...
- hdu 4625 Dice(概率DP)
Dice Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/Others) Total Submi ...
- hdu 4586 Play the Dice(概率dp)
Problem Description There is a dice with n sides, which are numbered from 1,2,...,n and have the equ ...
- HihoCoder - 1339 Dice Possibility(概率dp)
题意:求用N(1<=N<=100)个骰子掷出M(1<=M<=600)的概率 分析:直接求概率可能出现6^100次方,会爆精度.可以用一个数组dp[i][j]记录用i个骰子掷出j ...
- HihoCoder1339 Dice Possibility(概率DP+母函数)
时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 What is possibility of rolling N dice and the sum of the numb ...
- HDU 4652 Dice (概率DP)
版权声明:欢迎关注我的博客,本文为博主[炒饭君]原创文章,未经博主同意不得转载 https://blog.csdn.net/a1061747415/article/details/36685493 D ...
- Throwing Dice(概率dp)
C - Throwing Dice Time Limit:2000MS Memory Limit:32768KB 64bit IO Format:%lld & %llu Lig ...
随机推荐
- ACM2037
这题采用的是贪心算法,暂不会.
- 忘记gitlab的root密码
甚至也忘记了邮箱,或许是默认邮箱无法使用. 需要在服务器上面直接修改数据: gitlab-rails console production user = User.where().first user ...
- 解决Ubuntu Server 12.04换了网卡MAC地址后 网络不可用的问题.
重装了系统,新建了一个ubuntu虚拟机,加载原来的镜像,结果启动后网络变得不正常了,提示信息 Waiting for network configuration...Waiting up to 60 ...
- Object类中getClass()
Object类中包含一个方法名叫getClass,利用这个方法就可以获得一个实例的类型类.类型类指的是代表一个类型的类,因为一切皆是对象,类型也不例外,在Java使用类型类来表示一个类型.所有的类型类 ...
- ios 记录支付宝集成遇到的坑及解决方法
今天项目中要开始动手集成支付宝支付,在此小结一下.(目前新版的支付宝SDK有较大改版,去集成还需要自己去开发平台详细的按照集成步骤来完成https://doc.open.alipay.com/docs ...
- Java三大主流框架概述(转载)
转自:http://www.douban.com/note/320140839/ Struts.Hibernate和Spring是我们Java开发中的常用关键,他们分别针对不同的应用场景给出最合适的解 ...
- python如何使用 os.path.exists()--Learning from stackoverflow 分类: python 2015-04-23 20:48 139人阅读 评论(0) 收藏
Q&A参考连接 Problem:IOError: [Errno 2] No such file or directory. os.path.exists() 如果目录不存在,会返回一个0值. ...
- spring security3.2配置---权限管理
之前已经在我的博客中发过security的执行流程图了,大家能够先去看看那个图再看这篇.今天我主要在这里贴出了security配置中的几个重要的类和两个xml配置文件,基本上控制权限的就是这几个文件了 ...
- 自定义toast功能
http://download.csdn.net/detail/caryt/8105031
- Android_设备隐私获取,忽略6.0权限管理
1.前言 (1).由于MIUI等部分国产定制系统也有权限管理,没有相关api,故无法判断用户是否允许获取联系人等隐私.在Android 6.0之后,新增权限管理可以通过官方api判断用户的运行状态: ...