【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 ...
随机推荐
- 金蝶K3WISE常用数据表
K3Wise 14.2 清空密码update t_User set FSID=') F ", ,P T #8 *P!D &D 80!N &@ <0 C '+''''+' ...
- gnuplot生成MySQL QPS图形
1.建立MySQL QPS执行脚本 #!/bin/bash mysqladmin -uroot -p' extended-status -i1|awk \ 'BEGIN{flag=0; print & ...
- C# 应用程序配置文件App.Config和web.config
应用程序配置文件,对于asp.net是 web.config,对于WINFORM程序是 App.Config(ExeName.exe.config). 配置文件,对于程序本身来说,就是基础和依据,其本 ...
- Vim 编辑文件时,突然断开链接
centos 系统 编辑文本 突然退出 ,恢复文档操作: 有道笔记链接地址
- Python爬虫之三种网页抓取方法性能比较
下面我们将介绍三种抓取网页数据的方法,首先是正则表达式,然后是流行的 BeautifulSoup 模块,最后是强大的 lxml 模块. 1. 正则表达式 如果你对正则表达式还不熟悉,或是需要一些提 ...
- mac搭建lamp环境
转载:https://www.cnblogs.com/beautiful-code/p/7465320.html
- 【前端vue开发】vue项目使用sass less扩展语言所要安装的依赖
1.创建一个基于 webpack 模板的新项目 $ vue init webpack myvue 2.在当前目录下,安装依赖 $ cd myvue $ npm install 3.安装sass的依赖包 ...
- java基础35 双例集合Map及其常用方法
单例集合体系: ---------| collection 单例集合的根接口--------------| List 如果实现了list接口的集合类,具备的特点:有序,可重复 注:集合 ...
- 判断一个字符是否为数字的两种方法(C/C++)
在平时,我们经常遇见判断字符是否为数字这种题目,虽然感觉还是很简单,不过我是个更喜欢用函数的人,因为我觉得这样更便捷,所以我更推荐第二种方式. 1.直接判断 #include <stdio.h& ...
- HTML小工具
一般可能用的到的符号代码: 符号 HTML 符号 HTML & & < < > > ⁄ ⁄ " " ¸ ¸ ° ° ½ ½ ¼ ¼ ...