【POJ】2151:Check the difficulty of problems【概率DP】
| Time Limit: 2000MS | Memory Limit: 65536K | |
| Total Submissions: 8903 | Accepted: 3772 |
Description
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
Output
Sample Input
2 2 2
0.9 0.9
1 0.9
0 0 0
Sample Output
0.972
Source
Solution
概率DP
定义$dp[i][j][k]$表示第$i$个队伍做了$j$道题对了$k$道的概率。转移方程显然。
再定义$s[i][j]$表示第$i$个队对了不超过$j$道题的概率,$s[i][j]=\sum{dp[i][t][k]},0<=k<=j$
然后所有队伍都对了至少一道题的概率就是$p1=\prod{(1-s[i][0])}$
因为冠军队至少对了$n$道,那么最后的概率应该是$p1$减去每个队伍都没有达到$n$的概率:$\prod{s[i][n-1]}$,在这里要注意,还要保证每个队伍都至少对了1道题,因为是递推转移得到$s$,不能把$0$的贡献算进去,所以$s$从2开始递推。
Code
#include<iostream>
#include<cstdio>
using namespace std; double dp[][][], s[][], p[][];
int m, t, n; int main() {
while(scanf("%d%d%d", &m, &t, &n) != EOF) {
if(m == && t == && n == ) break;
for(int i = ; i <= t; i ++)
for(int j = ; j <= m; j ++)
scanf("%lf", &p[i][j]);
for(int i = ; i <= t; i ++) {
dp[i][][] = ;
for(int j = ; j <= m; j ++) {
dp[i][j][] = dp[i][j - ][] * ( - p[i][j]);
for(int k = ; k <= j; k ++)
dp[i][j][k] = dp[i][j - ][k - ] * p[i][j] + dp[i][j - ][k] * ( - p[i][j]);
}
for(int j = ; j <= m; j ++)
s[i][j] = dp[i][m][j];
}
for(int i = ; i <= t; i ++)
for(int j = ; j <= m; j ++)
s[i][j] = s[i][j] + s[i][j - ];
double p1 = ;
for(int i = ; i <= t; i ++) p1 *= ( - s[i][]);
double p2 = ;
for(int i = ; i <= t; i ++) p2 *= s[i][n - ];
if(n == ) p2 = ;
printf("%0.3lf\n", p1 - p2);
}
return ;
}
【POJ】2151:Check the difficulty of problems【概率DP】的更多相关文章
- POJ 2151 Check the difficulty of problems 概率dp+01背包
题目链接: http://poj.org/problem?id=2151 Check the difficulty of problems Time Limit: 2000MSMemory Limit ...
- [ACM] POJ 2151 Check the difficulty of problems (概率+DP)
Check the difficulty of problems Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4748 ...
- POJ 2151 Check the difficulty of problems (概率DP)
题意:ACM比赛中,共M道题,T个队,pij表示第i队解出第j题的概率 ,求每队至少解出一题且冠军队至少解出N道题的概率. 析:概率DP,dp[i][j][k] 表示第 i 个队伍,前 j 个题,解出 ...
- 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 Check the difficulty of problems Time Limit: 2000MS Memory Limit: 65536K ...
- poj 2151 Check the difficulty of problems(概率dp)
poj double 就得交c++,我交G++错了一次 题目:http://poj.org/problem?id=2151 题意:ACM比赛中,共M道题,T个队,pij表示第i队解出第j题的概率 问 ...
- POJ 2151 Check the difficulty of problems:概率dp【至少】
题目链接:http://poj.org/problem?id=2151 题意: 一次ACM比赛,有t支队伍,比赛共m道题. 第i支队伍做出第j道题的概率为p[i][j]. 问你所有队伍都至少做出一道, ...
- POJ 2151 Check the difficulty of problems (概率dp)
题意:给出m.t.n,接着给出t行m列,表示第i个队伍解决第j题的概率. 现在让你求:每个队伍都至少解出1题,且解出题目最多的队伍至少要解出n道题的概率是多少? 思路:求补集. 即所有队伍都解出题目的 ...
- [POJ2151]Check the difficulty of problems (概率dp)
题目链接:http://poj.org/problem?id=2151 题目大意:有M个题目,T支队伍,第i个队伍做出第j个题目的概率为Pij,问每个队伍都至少做出1个题并且至少有一个队伍做出N题的概 ...
- POJ2157 Check the difficulty of problems 概率DP
http://poj.org/problem?id=2151 题意 :t个队伍m道题,i队写对j题的概率为pij.冠军是解题数超过n的解题数最多的队伍之一,求满足有冠军且其他队伍解题数都大于等于1 ...
随机推荐
- mysql使用模板解决旧数据处理,默认初始化数据的通用方法!
一 业务介绍 先来看看我这得大致业务需求,这次业务比较简单: 即从现在开始,每次new一个爷爷都需要默认初始化给这个爷爷三个儿子(子表,爷爷id去关联),并在初始化每个儿子的同时再给每个儿子初始化若干 ...
- RabbitMQ学习(一):RabbitMQ要点简介
转载:http://blog.csdn.net/leixiaotao_java/article/details/78909760#t0 1.什么是RabbitMQ? RabbitMQ是由Erlang语 ...
- Git如何设置多个用户
前言 由于我们在使用GitHub时,通常不希望带有公司信息,所以需要独立的Git账户来提交练习代码,本文记录一下如何配置多个Git账户并创建公钥 正文 1.首先进入~/.ssh文件夹 2.然后创建一个 ...
- vue总结 04过渡--进入/离开 列表过渡
进入/离开 & 列表过渡 概述 Vue 在插入.更新或者移除 DOM 时,提供多种不同方式的应用过渡效果.包括以下工具: 在 CSS 过渡和动画中自动应用 class 可以配合使用第三方 CS ...
- 美国部分科技公司创始及IPO信息
作者:Ben.Z 时间:2018-04-19 做这份统计表格的目的是为了更好地了解当下美国的IT发展,搞清楚那些耳熟能详的名词的来源. 原文是用WPS统计的,本文仅展示截图. 创始人年龄分析: 1.上 ...
- python面向对象(三)之继承
继承 介绍 继承是从已有的类中派生出新的类,新的类能吸收已有类的数据属性和行为,并能扩展新的能力.继承即常说的is-a关系.子类继承父类的特征和行为,使得子类具有父类的各种属性和方法.或子类从父类继承 ...
- spark和hadoop比较
来源知乎 计算模型:hadoop-MapReduce,Spark-DAG(有向无环图)评注:经常有人说Spark就是内存版的MapReduce,实际上不是的.Spark使用的DAG计算模型可以有效的减 ...
- Unix IPC之Posix消息队列(3)
struct mq_attr { long mq_flags; /* message queue flag : 0, O_NONBLOCK */ long mq_maxmsg; /* max numb ...
- Java测试框架Mockito源码分析
1.Mockito简介 测试驱动的开发(Test Driven Design, TDD)要求我们先写单元测试,再写实现代码.在写单元测试的过程中,一个很普遍的问题是,要测试的类会有很多依赖,这些依赖的 ...
- afl入门学习
一个简单的示例 安装afl wget http://lcamtuf.coredump.cx/afl.tgz tar xfz afl.tgz cd afl-xxx sudo make install 用 ...