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
double dp[imax];
int n;
int main()
{
	int t,tt;
	scanf("%d",&t);
	for (tt=1;tt<=t;tt++)
	{
		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",tt,dp[0]);
	}
	return 0;
}
时间: 2024-10-10 01:24:29

Light OJ 1248 - Dice (III) 概率DP的相关文章

light oj 1248 - Dice (III)(期望)

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.

Light OJ 1030 - Discovering Gold(概率dp)

题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1030 题目大意:有一个很长的洞穴, 可以看做是1-n的格子.你的起始位置在1的地方, 每个格子中都有价值为v[i]的宝藏. 有一个6面的骰子,数字为从1-6, 每次摇一次骰子, 得到的数字x后, 你可以到达距离当前位置大x的位置, 并且得到那个位置的宝藏. 如果要走的位置在n的外面, 那么在此摇骰子, 直到找到一个合适的数字.到达n位置的时候结束. 现在想知道走到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

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

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

[DP] Light Oj 1017 Brush(III)

题目为 light oj 1017. 现在是凌晨两点二十分,我却毫无睡意,这题折腾了我一个晚上,一直没有做对,最后发现转移方程忽略了一个重要的条件,泪奔-. 干脆不睡觉,写一篇题解警醒自己,也算是对于自己考虑问题智障的惩罚. 我真是个智障 0 s 0 ..... 题目大意是 , 给你N个二维坐标上的点 (x,y) , 每一个点代表一个污渍,现在有一把宽度为 W 的刷子,平行于 x 轴移动 K 次,问,最多能擦掉多少污渍. 很明显这题和x坐标一点关系都没有(因为刷子沿着平行x轴移动,并可以移动无限

[lLOJ 1248] Dice (III)

G - Dice (III) Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%lld & %llu Description 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

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.

LightOJ 1248 - Dice (III) 给一个质地均匀的n的骰子, 求投掷出所有点数至少一次的期望次数。(概率)

题意:http://www.lightoj.com/volume_showproblem.php?problem=1248 投掷出第一个未出现的点数的概率为n/n = 1, 因为第一次投掷必然是未出现的. 第二个未出现的点数第一次出现的概率为 (n - 1) / n,因为有一个已经投掷出现过. 第i个未出现的点数第一次出现的概率为 (n - i) / i, 这满足几何分布. 其期望E = 1/p 所以期望为n *(1 + 1 / 2 + 1 / 3 + ... 1 / n). #include<