POJ 2151 Check the difficulty of problems(dp,求概率)
来源:互联网 发布:清华附属小学网络课程 编辑:程序博客网 时间:2024/05/16 07:01
题目大意:
求每个队伍都至少做出一题,并且有人做题数大于等于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;}
0 0
- POJ 2151 Check the difficulty of problems(dp,求概率)
- POJ 2151 Check the difficulty of problems 概率DP
- poj 2151 Check the difficulty of problems 概率dp
- POj 2151 Check the difficulty of problems 概率DP
- POJ 2151 Check the difficulty of problems(概率DP)
- 概率dp POJ 2151 Check the difficulty of problems
- poj 2151 Check the difficulty of problems(概率dp)
- poj 2151 Check the difficulty of problems(概率dp)
- POJ 2151 Check the difficulty of problems(概率dp)
- poj 2151 Check the difficulty of problems 概率dp
- poj 2151 Check the difficulty of problems(概率DP)
- poj 2151 Check the difficulty of problems(概率dp)
- poj 2151 Check the difficulty of problems 概率dp
- poj 2151 Check the difficulty of problems (概率dp)
- POJ 2151 Check the difficulty of problems (概率dp)
- poj 2151 Check the difficulty of problems (概率DP)
- poj 2151 Check the difficulty of problems (dp,概率)
- Check the difficulty of problems - POJ 2151 概率dp
- 深入理解Linux网络技术内幕——内核基础架构和组件初始化
- 工作记录--linux常用命令
- 使用tornado的gen.coroutine进行异步编程
- (十)弹出框Alert与ActionSheet
- Comet框架Pushlets的集成
- POJ 2151 Check the difficulty of problems(dp,求概率)
- 黑马程序员——c语言学习---变量与存储
- __attribute__ 你知多少?
- 根据xml生成xsd,然后根据xsd生成javabean
- Latex按照章节为公式编号
- 对比Tornado和Twisted
- hdu 1260 Tickets 【dp】
- Linux tar打包命令
- 关于Android沉浸式通知栏的一个开源库SystemBarTint简单使用