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 ...
随机推荐
- Android SlidingMenu 滑出侧边栏
最近有个项目需要使用侧边栏,而且希望是左右两侧都能够滑出侧边菜单,在网上查找实现方式时,发现大家用的最多的还是大神jfeinstein10的SlidingMenu库,地址https://github. ...
- CentOS搭建GIT服务器【一】-仓库搭建以及基于gitosis的SSH方式访问
1.安装GIT核心 yum install curl-devel expat-devel gettext-devel openssl-devel zlib-devel perl-devel gcc g ...
- [转]在 Mac OS X 终端里使用 Solarized 配色方案
相信长期浸泡在终端和代码的小伙伴们都有一套自己喜爱的配色方案.以前一直在用简单.适合阅读的 Terminal.app 配色方案,换到 MacBook Pro with Retina display 后 ...
- kafka broker 进入 conflicted ephemeral node 死循环
转载请注明原创地址 http://www.cnblogs.com/dongxiao-yang/p/5621303.html 最近发现kafka一台服务器producer客户端写入时一直报错,查看该br ...
- js去除空格
function trim(str){ return str.replace(/(^\s*) | ( \s*$ )/g,"" ); }
- [TypeScript] Function Overloads in Typescript
It's common in Javascript for functions to accept different argument types and to also return differ ...
- Windows XP下安装WinCE6.0开发环境
Windows下怎样编译WinCE6.0及开发应用程序.以下介绍(安装之前必须保证C盘有足够的空间!20g左右!主要是由于在安装程序在安装过程中要解压): 在Visual Studio 2005之前, ...
- CHENEY-YANG'S BLOG(cheney-yang)
This is Cheney-Yang's blog ! Welcome to here ! This is Cheney-Yang's blog ! Welcome to here ! This i ...
- Linux下搭建Oracle11g RAC(7)----安装Oracle 软件
从此步骤开始,我们正式安装oracle软件: ① 以oracle用户登录图形界面,执行/home/oracle/database/runInstaller,进入OUI的图形安装界面: ② 进入OUI安 ...
- 【Android】数据库的简单应用——创建数据库
SQLiteOpenHelper是一个抽象类,要使用它必须写一个类继承它.SQLiteOpenHelper有两个抽象方法onCreate()和onUpgrade(),我们要在类里面重写这两个方法来实现 ...