POJ 2151 Check the difficulty of problems(dp,求概率)

题目大意:

求每个队伍都至少做出一题,并且有人做题数大于等于N的概率。

解题思路:

dp[i][j][k]表示第i支队伍在前j道题中做出k道的概率。

转移方程为: dp[i][j][k] = dp[i][j-1][k] * (1 - p[i][j]) + dp[i][j-1][k-1] * p[i][j];

用s[i][j]表示第i支队伍作出的题目小于等于j的概率。

则s[i][j] = dp[i][M][0] + dp[i][M][1] + ....... + dp[i][M][j];

p1表示每个队伍都至少做出一道题的概率, p1 = (1 - s[1][0]) * (1 - s[2][0]) * ...... * (1 - s[T][0]);

p2 表示每个队伍做的题目都在1 到 N-1之间的概率 : p2 = (s[1][N-1] - s[1][0]) * (s[2][N-1]  - s[2][0]) * ...... * (s[T][N-1]  - s[T][0]);

则ans = p1 - p2;

#include <iostream>
#include <cstring>
#include <cstdlib>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <stack>
using namespace std;
double dp[1010][35][35];
double p[1010][1010];
double s[1010][1010];
int M, T, N;
int main()
{
	while(scanf("%d%d%d", &M, &T, &N)!=EOF)
	{
		if(M == 0 && T == 0 && N == 0)
			break;
		for(int i=1;i<=T;i++)
		{
			for(int j=1;j<=M;j++)
			{
				scanf("%lf", &p[i][j]);
			}
		}
		for(int i=0;i<=T;i++) dp[i][0][0] = 1;
		for(int i=1;i<=T;i++)
		{
			for(int j=1;j<=M;j++)
			{
				dp[i][j][0] = dp[i][j-1][0] * (1 - p[i][j]);
			}
		}
		for(int i=1;i<=T;i++)
		{
			for(int j=1;j<=M;j++)
			{
				for(int k=1;k<=j;k++)
				{
					dp[i][j][k] = dp[i][j-1][k] * (1 - p[i][j]) + dp[i][j-1][k-1] * p[i][j];
				}
			}
		}
		for(int i=1;i<=T;i++) s[i][0] = dp[i][M][0];
		for(int i=1;i<=T;i++)
		{
			for(int j=1;j<=M;j++)
				s[i][j] = s[i][j-1] + dp[i][M][j];
		}
		double p1 = 1, p2 = 1;
		for(int i=1;i<=T;i++)
			p1 *= (1 - s[i][0]);
		for(int i=1;i<=T;i++)
			p2 *= (s[i][N-1] - s[i][0]);
		printf("%.3lf\n", p1 - p2);
	}
	return 0;
}
时间: 2024-10-14 22:58:38

POJ 2151 Check the difficulty of problems(dp,求概率)的相关文章

POJ 2151 Check the difficulty of problems (动态规划-概率DP)

Check the difficulty of problems Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4522   Accepted: 1993 Description Organizing a programming contest is not an easy job. To avoid making the problems too difficult, the organizer usually exp

poj 2151 Check the difficulty of problems(线段树+概率)

Check the difficulty of problems Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4465   Accepted: 1966 Description Organizing a programming contest is not an easy job. To avoid making the problems too difficult, the organizer usually exp

poj 2151 Check the difficulty of problems (dp,概率)

链接:poj 2151 题意:比赛中有M道题,T个参赛队,pij表示第i队解出第j题的概率, 求每队至少解出一题,且冠军队至少解出N道题的概率 分析:要求每队至少解出一题,且冠军队至少解出N道题的概率 则原来的所求的概率可以转化为: 每队均至少做一题的概率P1 减去 每队做题数均在1到N-1之间的概率P2 设dp[i][j][k]表示第i队在前j道题解出k道题的概率 则dp[i][j][k]=dp[i][j-1][k-1]*pij+dp[i][j-1][k]*(1-pij) 设sum[i][j]

POJ 2151 Check the difficulty of problems (概率dp)

题意:给出m.t.n,接着给出t行m列,表示第i个队伍解决第j题的概率. 现在让你求:每个队伍都至少解出1题,且解出题目最多的队伍至少要解出n道题的概率是多少? 思路:求补集. 即所有队伍都解出题目的概率,减去所有队伍解出的题数在1~n-1之间的概率 这里关键是如何求出某个队伍解出的题数在1~n-1之间的概率,采用dp的方法: 用p(i,j)表示前i道题能解出j道的概率,有p(i,j)=p(i-1,j)*(1-p(i))+p(i-1,j-1)*p(i)p(i)表示解出第i题的概率. #inclu

poj 2151 Check the difficulty of problems

dp[i][j][s]表示第i个人,在前j个问题解决了s个问题 dp[i][j][s]=dp[i][j-1][s-1]*p[i][j]+dp[i][j-1][s]*(1-p[i][j]); 1 #include<iostream> 2 #include<string> 3 #include<cstdio> 4 #include<vector> 5 #include<queue> 6 #include<stack> 7 #include

poj 2151 Check the difficulty of problems (检查问题的难度)

poj 2151 Check the difficulty of problems http://poj.org/problem?id=2151 题意:此刻有tn道题目,有dn个队伍,知道每个队伍能答对每个题目的概率,问:冠军至少答对n(1<=n<=tn)道题目,其他队伍至少要答对一道题目的概率 dp+概率 方法: f[i][j]第i队做对第j个题的概率 g[i][j][k]第i队前j个题做对k个题的概率 状态转移方程:g[i][j][k] = g[i][j-1][k-1]*f[i][j] +

POJ 2151 Check the difficulty of problems(概率dp)

Language: Default Check the difficulty of problems Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 5419   Accepted: 2384 Description Organizing a programming contest is not an easy job. To avoid making the problems too difficult, the org

[ACM] POJ 2151 Check the difficulty of problems (概率+DP)

Check the difficulty of problems Time Limit: 2000MS   Memory Limit: 65536K Total Submissions: 4748   Accepted: 2078 Description Organizing a programming contest is not an easy job. To avoid making the problems too difficult, the organizer usually exp

POJ 2151 Check the difficulty of problems(概率dp啊)

题目链接:http://poj.org/problem?id=2151 Description Organizing a programming contest is not an easy job. To avoid making the problems too difficult, the organizer usually expect the contest result satisfy the following two terms: 1. All of the teams solv