POJ2151-Check the difficulty of problems
题目链接:点击打开链接
Check the difficulty of problems
Time Limit: 2000MS | Memory Limit: 65536K | |
Total Submissions: 8583 | Accepted: 3656 |
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?
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 2
0.9 0.9
1 0.9
0 0 0
Sample Output
0.972
题目大意:给出几个队,几道题,第一名至少A的题数N,求每队都至少有一道A并且冠军队伍达到N题的概率
思路:只知道是概率dp(神犇说是简单的dp)主要还是怎么规划好状态。(初始化和状态转移方程)
AC代码:
#include<iostream>
#include<cstdio>
using namespace std;
int M, T, N;
double dp[1010][50][50];//dp[i][j][k] 第i队前j题过k道的概率
double s[1010][50];//s[i][k] 第i队过小于等于k的概率
double p[1010][50];
int main() {
while(~scanf("%d %d %d", &M, &T, &N)) {
if(M+T+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 = 1; i <= T; i++) {
dp[i][0][0] = 1;//前0题过0道概率为1
for(int j = 1; j <= M; j++) {
dp[i][j][0] = dp[i][j-1][0] * (1-p[i][j]);//前j题过0道 = 前j-1题概率 * 本题不过概率
}
for(int j = 1; j <= M; j++) { //前j题过k道 = 前j-1题过k-1道的概率 * 本题过的概率 + 前j-1题过k道 * 本题不过概率
for(int k = 1; k <= j; k++) { //写成了k <= M
dp[i][j][k] = dp[i][j-1][k-1] * p[i][j] + dp[i][j-1][k] * (1-p[i][j]);
}
}
s[i][0] = dp[i][M][0];//过小于等于0道概率 就是前M题过0道概率
for(int k = 1; k <= M; k++) {
s[i][k] = s[i][k-1] + dp[i][M][k];// s[i][k] = dp[i][M][0] + dp[i][M][1] + ...+ dp[i][M][k];
}
}
double P1 = 1;
double P2 = 1;
for(int i = 1; i <= T; i++) {
P1 *= (1-s[i][0]); // 所有队都至少过一道概率
P2 *= (s[i][N-1] - s[i][0]); //所有对都过 1~N-1道 概率
}
printf("%.3lf\n", P1-P2);
}
}
POJ2151-Check the difficulty of problems的更多相关文章
- [POJ2151]Check the difficulty of problems (概率dp)
题目链接:http://poj.org/problem?id=2151 题目大意:有M个题目,T支队伍,第i个队伍做出第j个题目的概率为Pij,问每个队伍都至少做出1个题并且至少有一个队伍做出N题的概 ...
- [poj2151]Check the difficulty of problems概率dp
解题关键:主要就是概率的推导以及至少的转化,至少的转化是需要有前提条件的. 转移方程:$dp[i][j][k] = dp[i][j - 1][k - 1]*p + dp[i][j - 1][k]*(1 ...
- POJ 2151 Check the difficulty of problems
以前做过的题目了....补集+DP Check the difficulty of problems Time Limit: 2000MS Memory Limit: 65536K ...
- Check the difficulty of problems
Check the difficulty of problems Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 5830 Acc ...
- Check the difficulty of problems(POJ 2151)
Check the difficulty of problems Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 5457 ...
- POJ 2151 Check the difficulty of problems (动态规划-可能DP)
Check the difficulty of problems Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4522 ...
- POJ 2151 Check the difficulty of problems 概率dp+01背包
题目链接: http://poj.org/problem?id=2151 Check the difficulty of problems Time Limit: 2000MSMemory Limit ...
- 【POJ】2151:Check the difficulty of problems【概率DP】
Check the difficulty of problems Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 8903 ...
- [ACM] POJ 2151 Check the difficulty of problems (概率+DP)
Check the difficulty of problems Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4748 ...
- 【poj2151】 Check the difficulty of problems
http://poj.org/problem?id=2151 (题目链接) 题意 T支队伍,一共M道题,第i支队伍解出第j道题的概率为p[i][j].问每支队伍至少解出1道题并且解题最多的的队伍至少解 ...
随机推荐
- Linux-解决putty无法直接使用root用户远程登录linux主机的问题
问题描述: 有时,在使用putty连接远程linux主机时会发现,无法直接使用root登录, 但是可以使用其他用户登录,然后切换至root用户. 解决办法: 1.修改配置文件 vi /etc/ssh/ ...
- Convolutional Neural Networks for Visual Recognition 7
Two Simple Examples softmax classifier 后,我们介绍两个简单的例子,一个是线性分类器,一个是神经网络.由于网上的讲义给出的都是代码,我们这里用公式来进行推导.首先 ...
- 继续学习:C语言关键字
auto :声明自动变量 break:跳出当前循环 case:开关语句分支 char :声明字符型变量或函数 const :声明只读变量 continue:结束当前循环,开始下一轮循环 default ...
- bzoj 2118: 墨墨的等式 spfa
题目: 墨墨突然对等式很感兴趣,他正在研究\(a_1x_1+a_2y_2+ ... +a_nx_n=B\)存在非负整数解的条件,他要求你编写一个程序,给定\(N,\{a_n\}\)以及\(B\)的取值 ...
- Unity3d中SendMessage 用法
Message相关有3条指令:SendMessage ("函数名",参数,SendMessageOptions) //GameObject自身的ScriptBroadcastM ...
- POJ2559:Largest Rectangle in a Histogram
浅谈栈:https://www.cnblogs.com/AKMer/p/10278222.html 题目传送门:http://poj.org/problem?id=2559 贪心的想,最大的子矩阵顶部 ...
- POJ1995:Raising Modulo Numbers
二进制前置技能:https://www.cnblogs.com/AKMer/p/9698694.html 题目传送门:http://poj.org/problem?id=1995 题目就是求\(\su ...
- UILabel常见用法
//创建一个UILabel UILabel *label1 = [[UILabel alloc] initWithFrame:CGRectMake(50 , 100 , 200 , 560)]; // ...
- hashCode之二--Java:重写equals()和hashCode()
以下内容总结自<Effective Java>. 1.何时需要重写equals() 当一个类有自己特有的“逻辑相等”概念(不同于对象身份的概念). 2.设计equals() [1]使用in ...
- Centos环境docker的正确安装及疑难杂症
根据官方文档:https://docs.docker.com/install/linux/docker-ce/centos/搭建docker 1.卸载docker旧版本: sudo yum remov ...