POJ2151 : Check the difficulty of problems
来源:互联网 发布:mac移动硬盘无法分区 编辑:程序博客网 时间:2024/06/09 18:15
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 solve at least one problem.
2. The champion (One of those teams that solve the most problems) solves at least a certain number of problems.
Now the organizer has studied out the contest problems, and through the result of preliminary contest, the organizer can estimate the probability that a certain team can successfully solve a certain problem.
Given the number of contest problems M, the number of teams T, and the number of problems N that the organizer expect the champion solve at least. We also assume that team i solves problem j with the probability Pij (1 <= i <= T, 1<= j <= M). Well, can you calculate the probability that all of the teams solve at least one problem, and at the same time the champion team solves at least N problems?
1. All of the teams solve at least one problem.
2. The champion (One of those teams that solve the most problems) solves at least a certain number of problems.
Now the organizer has studied out the contest problems, and through the result of preliminary contest, the organizer can estimate the probability that a certain team can successfully solve a certain problem.
Given the number of contest problems M, the number of teams T, and the number of problems N that the organizer expect the champion solve at least. We also assume that team i solves problem j with the probability Pij (1 <= i <= T, 1<= j <= M). Well, can you calculate the probability that all of the teams solve at least one problem, and at the same time the champion team solves at least N problems?
Input
The input consists of several test cases. The first line of each test case contains three integers M (0 < M <= 30), T (1 < T <= 1000) and N (0 < N <= M). Each of the following T lines contains M floating-point numbers in the range of [0,1]. In these T lines, the j-th number in the i-th line is just Pij. A test case of M = T = N = 0 indicates the end of input, and should not be processed.
Output
For each test case, please output the answer in a separate line. The result should be rounded to three digits after the decimal point.
Sample Input
2 2 20.9 0.91 0.90 0 0
Sample Output
0.972
思路分析:
因为是我们最后需要算各个队伍各自解决问题个数的概率
我们开一个三维数组 F[i][j][k]表示第 i 支队伍在前 j 道题中共解决了 k 道题。
然后开一个二维数组 S[i][k] 这个数组的作用在后面再说。
首先我们清零F数组,我们可以很容易的知道这个数组中某些元素的值
比如 F[i][0][0] = 1.0 第i支队伍在前0道题中解决0道题的概率肯定是1.0
还有 F[i][j][0] = F[i][j-1][0] * ( 1 - P[i][j])
前j道题中 做出0道题的概率 等于 前j-1道题中 做出 0 道题的概率 乘上 第j道题做不出来的概率
把这些很显然的元素放进去之后,我们就得到了F的边界状态了。
然后尝试写出状态转移方程:
F[i][j][k] = F[i][j-1][k] * (1 - P[i][j]) + F[i][j-1][k-1] * P[i][j]
然后我们看看S[i][k]这个数组中保存的是什么东西...
先给出S[i][k]是怎么得到的
S[i][k] = F[i][M][0] + F[i][M][1] + F[i][M][2] + ... + F[i][M][k]
他的意思是:第i支队伍做出 不超过k道题 的概率
在所有题中做出0道,做出1道,做出2道,做出3道...做出k道。
S[i][M] - S[i][0] 就表示第 i 支队伍做出 至少一道题 的概率
同理 S[i][N-1]-S[i][0]就表示第 i 支队伍做出的题在 1 到 N-1 道之间的概率
那么我们把所有队伍的这两个概率连乘,得到两个概率P1,P2。
P1 表示 所有队伍至少做出一道题的概率
P2 表示 所有队伍至少做出一道题,且至多做出N-1道题的概率
P1 - P2 就表示 所有队伍至少做出一道题,且有队伍做出至少 N 道题的概率,也就是我们的计算目标。
代码如下:
#include <stdio.h>#include <stdlib.h>#include<string.h>double F[1010][35][35];double P[1010][35];double S[1010][35];int main(){ int M,T,N; int i,j,k; double P1,P2; while(scanf("%d %d %d",&M,&T,&N) != EOF) { if(!M && !N && !T) break; memset(F,0,sizeof(F)); memset(S,0,sizeof(S)); for(i=1;i<=T;i++) for(j=1;j<=M;j++) scanf("%lf",&P[i][j]); for(i=1;i<=T;i++) { F[i][0][0] = 1.0; for(j=1;j<=M;j++) F[i][j][0] = F[i][j-1][0] * (1 - P[i][j]); for(j=1;j<=M;j++) for(k=1;k<=j;k++) F[i][j][k] = F[i][j-1][k]*(1-P[i][j]) + F[i][j-1][k-1] * P[i][j]; S[i][0] = F[i][M][0]; for(k=1;k<=M;k++) S[i][k] = S[i][k-1] + F[i][M][k]; } P1 = P2 = 1.0; for(i = 1; i<=T; i++) P1 *= (S[i][M]-S[i][0]); for(i = 1; i<=T; i++) P2 *= (S[i][N-1]-S[i][0]); printf("%.3f\n",P1-P2); } return 0;}
0 0
- POJ2151-Check the difficulty of problems
- Check the difficulty of problems poj2151
- POJ2151--Check the difficulty of problems
- POJ2151-Check the difficulty of problems
- 【POJ2151】【Check the difficulty of problems】
- POJ2151 : Check the difficulty of problems
- poj2151(Check the difficulty of problems) dp
- poj2151 Check the difficulty of problems
- poj2151 Check the difficulty of problems
- POJ2151 Check the difficulty of problems 概率+DP
- POJ2151:Check the difficulty of problems(概率DP)
- POJ2151-Check the difficulty of problems(概率DP)
- POJ2151----Check the difficulty of problems(概率dp)
- POJ2151- Check the difficulty of problems(概率DP)
- POJ2151——Check the difficulty of problems
- poj2151 Check the difficulty of problems(概率dp)
- (POJ2151)Check the difficulty of problems <概率DP>
- poj2151 Check the difficulty of problems 概率dp
- ios pickerView 点菜
- 每周小结-3 D3 on AngularJS
- 从va_list、va_start、va_arg、va_end想到了vsprintf的源码
- PHP入门学习笔记之—— 分享 PHP 理论+实践学习网站
- OC阅读笔记十八:僵尸对象(Zombie Object)
- POJ2151 : Check the difficulty of problems
- 工作四年的迷茫
- Apache James配置个人笔记(完整解决DNS问题), 网页版的参考 Claros In Touch webmail(Pop3/IMAP)
- 数据库1
- 数组去重
- View绘制流程(3)----view的绘制流程及自定义View的相关问题
- vs2013 窗体应用编程—控件大小随窗体变化(通过代码实现)
- CodeForces 589D Boulevard (一维区间判断相交 非线段交做法)
- 全面学习观和创新学习观