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].。这个从后往前。
时间: 2024-10-10 01:24:36

Dice (III) 概率dp的相关文章

Light OJ 1248 - Dice (III) 概率DP

n个面的骰子 求每个面至少扔到一次的期望值 设dp[i]为已经扔了i个不同面的期望值 dp[n] = 0 求dp[0] 因为dp[i]为还需要扔i个不同的面 每次可能扔中已经扔过的面或者没有扔到过的面2中情况 所以dp[i] = (i/n)*dp[i] + (n-i)/n*dp[i+1] +1 等号2边都有dp[i] 移项得dp[i] = dp[i+1]+n/(n-i) #include <cstdio> #include <cstring> #define imax 100005

HDU 4652 Dice (概率DP)

Dice Problem Description You have a dice with m faces, each face contains a distinct number. We assume when we tossing the dice, each face will occur randomly and uniformly. Now you have T query to answer, each query has one of the following form: 0

LightOJ1248---Dice (III)(概率dp)

Given a dice with n sides, you have to find the expected number of times you have to throw that dice to see all its faces at least once. Assume that the dice is fair, that means when you throw the dice, the probability of occurring any face is equal.

HihoCoder1339 Dice Possibility(概率DP+母函数)

时间限制:10000ms 单点时限:1000ms 内存限制:256MB 描述 What is possibility of rolling N dice and the sum of the numbers equals to M? 输入 Two integers N and M. (1 ≤ N ≤ 100, 1 ≤ M ≤ 600) 输出 Output the possibility in percentage with 2 decimal places. 样例输入 2 10 样例输出 8.3

HihoCoder - 1339 Dice Possibility(概率dp)

题意:求用N(1<=N<=100)个骰子掷出M(1<=M<=600)的概率 分析:直接求概率可能出现6^100次方,会爆精度.可以用一个数组dp[i][j]记录用i个骰子掷出j的概率.i为0时无论j是多少,概率都是0.i为1时,j从1-6的概率都是1/6.其余可以递推得到 dp[i][j]  = 0 (j<i || j>6*i),sigma(dp[i-1][max(0,j-k)])  (1<=k<=6) #include<stdio.h> #in

HDU 4652 Dice(概率dp)

Problem Description You have a dice with m faces, each face contains a distinct number. We assume when we tossing the dice, each face will occur randomly and uniformly. Now you have T query to answer, each query has one of the following form: 0 m n:

LightOJ - 1248 Dice (III) 期望 + dp

题目大意:给出一个n面的色子,问看到每个面的投掷次数期望是多少 解题思路:水题啊,竟然被卡了那么久,也是醉了,给题目所给的那个样例误导了...不怪那个 怪自己太弱了,还得继续训练啊... 设dp[i]表示扔到i个不同面的期望,那么 dp[i + 1] = i / n * dp[i + 1] + (n - i) / n * dp[i] + 1 整理得 dp[i + 1] = n / (n - i) + dp[i] + 1 #include<cstdio> #define maxn 100010

Throwing Dice(概率dp)

C - Throwing Dice Time Limit:2000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu LightOJ 1064 uDebug Description n common cubic dice are thrown. What is the probability that the sum of all thrown dice is at least x? Input Input starts wit

HDU 4599 Dice (概率DP+数学+快速幂)

题意:给定三个表达式,问你求出最小的m1,m2,满足G(m1) >= F(n), G(m2) >= G(n). 析:这个题是一个概率DP,但是并没有那么简单,运算过程很麻烦. 先分析F(n),这个用DP来推公式,d[i],表示抛 i 次连续的点数还要抛多少次才能完成.那么状态转移方程就是 d[i] = 1/6*(1+d[i+1]) + 5/6*(1+d[1]), 意思就是说在第 i 次抛和上次相同的概率是1/6,然后加上上次抛的和这一次,再加上和上次不同的,并且又得从第1次开始计算. 边界就是