Light OJ 1317 Throwing Balls into the Baskets 概率DP

?n个人 m个篮子 每一轮每一个人能够选m个篮子中一个扔球 扔中的概率都是p 求k轮后全部篮子里面球数量的期望值

依据全期望公式 进行一轮球数量的期望值为dp[1]*1+dp[2]*2+...+dp[n]*n 记为w

当中dp[i]为i个人扔中的概率 dp[i] = C(n, i)*p^i*(1-p)^(n-i) 终于答案为w*k

#include <cstdio>
#include <cstring>
using namespace std;
double dp[20];
double a[20], b[20];

double cm(int n, int m)
{
	double ans = 1;
	for(int i = 1; i <= m; i++)
	{
		ans *= (double)n--;
		ans /= (double)i;
	}
	return ans;
}
int main()
{
	int T;
	int cas = 1;
	scanf("%d", &T);
	while(T--)
	{
		int n, m, k;
		double p;
		scanf("%d %d %d %lf", &n, &m, &k, &p);
		dp[0] = a[0] = b[0] = 1;
		for(int i = 1; i <= n; i++)
		{
			a[i] = a[i-1]*p;
			b[i] = b[i-1]*(1-p);
		}
		for(int i = 0; i <= n; i++)
		{
			dp[i] = cm(n, i)*a[i]*b[n-i];
		}
		double ans = 0;
		for(int i = 1; i <= n; i++)
			ans += dp[i]*(double)i;
		ans *= (double)k;
		printf("Case %d: %.10lf\n", cas++, ans);
	}
	return 0;
}
时间: 2024-08-06 03:43:30

Light OJ 1317 Throwing Balls into the Baskets 概率DP的相关文章

lightOJ 1317 Throwing Balls into the Baskets

lightOJ  1317  Throwing Balls into the Baskets(期望)  解题报告 题目链接:http://acm.hust.edu.cn/vjudge/contest/view.action?cid=88890#problem/A 题目: Description You probably have played the game "Throwing Balls into the Basket". It is a simple game. You have

LightOJ1317---Throwing Balls into the Baskets (概率dp)

You probably have played the game "Throwing Balls into the Basket". It is a simple game. You have to throw a ball into a basket from a certain distance. One day we (the AIUB ACMMER) were playing the game. But it was slightly different from the m

LightOJ - 1317 Throwing Balls into the Baskets 期望

题目大意:有N个人,M个篮框,K个回合,每个回合每个人可以投一颗球,每个人的命中率都是相同的P,问K回合后,投中的球的期望数是多少 解题思路:因为每个人的投篮都是一个独立的事件,互不影响,所以每回合投中的球的期望数是相同的 只需求得一回合的期望再乘上K就答案了 #include<cstdio> #define maxn 100 double ans, p; int n, m, k; int c[20][20]; void init() { c[1][1] = c[1][0] = 1; for(

Light OJ 1038 - Race to 1 Again(概率DP)

题目的意思是说任何一个大于1的整数,经过若干次除以自己的因子之后可以变为1, 求该变换字数的数学期望值. 题目分析: 我们设置dp[n] 为数字n的期望.假设n的因子为k1, k2, k3.... 共有k个 那么 dp[n] = (dp[k1] + dp[k2] +..... + dp[n] + k)* (1/k) 公式化简一下: dp[n] = (1/(k-1)) * (dp[k1] + dp[k2] .........+dp[n] + k) 式子出来记忆化搜索一下 =============

九度oj 题目1546:迷宫问题 (概率dp guess消元)

题目链接:点击打开链接 题目描述: 给定一个n*m的迷宫,如 S.. ..# E.E 其中,S代表开始位置,#代表不可行走的墙,E代表出口. 主人公从开始位置出发,每次等概率的随机选择下一个可以行走的位置,直到到达某一个出口为止. 现在他想知道,在这一概率事件中,它从开始位置走到某一个出口的期望步数是多少. 输入: 输入包含多组测试用例,每组测试用例由两个整数n,m(1<=n,m<=15)开始,代表迷宫的大小 接下去n行每行m个字符描述迷宫信息,具体规则如题面所述. 数据保证至少存在一个E和一

light oj 1317

Description You probably have played the game "Throwing Balls into the Basket". It is a simple game. You have to throw a ball into a basket from a certain distance. One day we (the AIUB ACMMER) were playing the game. But it was slightly differen

Light OJ 1064 - Throwing Dice

题目大意: 给你n个骰子, 问点数大于等于x的概率是多少? #include<cstdio> #include<cstring> #include<iostream> #include<algorithm> #include<cmath> #include<queue> #include<vector> #include<map> using namespace std; typedef long long L

LightOj_1317 Throwing Balls into the Baskets

题目链接 题意: 有N个人, M个篮框, 每个人投进球的概率是P. 问每个人投K次后, 进球数的期望. 思路: 每个人都是相互独立的, 求出一个人进球数的期望即可. 进球数和篮框的选择貌似没有什么关系, 所以给的这个M并没有什么卵用.... 每个人进球数的期望为:E = sigma (i * C(K, i) * p ^ i * (1 - p) ^ (k - i)); 总的进球数期望为:N * E 代码: 1 #include <cmath> 2 #include <cstdio>

Light OJ 1025 - The Specials Menu(动态规划-区间dp)

题目链接:http://www.lightoj.com/volume_showproblem.php?problem=1025 题目大意:一串字符, 通过删除其中一些字符, 能够使这串字符变成回文串. 现在给你一串字符,问能够得到多少种不同的回文串: 注意:字符串"abba", 可以得到9串回文串,分别为'a', 'a', 'b', 'b', 'aa', 'bb', 'aba', 'aba', 'abba'. 解题思路:声明dp[i][j]为字符串[i,j]区间中通过删除可以得到不同回