Check the difficulty of problems - poj 2151 (概率+DP)
有 T(1<T<=1000) 支队伍和 M(0<M<=30) 个题目,已知每支队伍 i 解决每道题目 j 的的概率 p[i][j],现在问:每支队伍至少解决一道题,且解题最多的队伍的题目数量不少于 N(0<N<=M) 的概率是多少?
p[i][j]表示第i个队伍做对第j题的概率。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]);
再求出每个队都至少做对 1 道题的概率:ans1 *= 1 - dp[i][m][0];
求出每个队都只做对了 1 ~ n-1 题的概率 ans2即:(把每个队做对 1 ~ n-1 题的概率相加后,并把每个队的结果相乘);
然后两者相减ans1-ans2
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int M,T,N;
double p[][];
double dp[][][];
double sum[][];
int main() {
scanf("%d %d %d",&M,&T,&N);
while(M&&N&&T){
memset(p,,sizeof(p));
for(int i=;i<=T;i++){
for(int j=;j<=M;j++){
scanf("%lf",&p[i][j]);
}
}
memset(dp,,sizeof(dp));
for(int i=;i<=T;i++){
dp[i][][]=p[i][];
dp[i][][]=-p[i][]; }
for(int i=;i<=T;i++){
for(int j=;j<=M;j++){
for(int k=;k<=j;k++){
dp[i][j][k]=dp[i][j-][k]*(1.0-p[i][j]);
if(k>) dp[i][j][k]+=dp[i][j-][k-]*p[i][j];
}
}
}
memset(sum,,sizeof(sum));
for(int i=;i<=T;i++){
sum[i][]=dp[i][M][];
for (int j=;j<=M;j++) {
sum[i][j]=sum[i][j-]+dp[i][M][j];
}
}
double ans1=1.0,ans2=1.0;
for(int i=; i<=T; i++) {
ans1*=sum[i][M]-sum[i][];
ans2*=(sum[i][N-]-sum[i][]);
}
printf("%.3lf\n",ans1-ans2);
scanf("%d %d %d",&M,&T,&N);
} return ;
}
| Time Limit: 2000MS | Memory Limit: 65536K | |
| Total Submissions: 5766 | Accepted: 2515 |
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
Check the difficulty of problems - poj 2151 (概率+DP)的更多相关文章
- POJ 2151 Check the difficulty of problems (动态规划-可能DP)
Check the difficulty of problems Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4522 ...
- poj 2151 概率DP(水)
Check the difficulty of problems Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 5750 ...
- POJ 2151 概率DP
主要的子问题是每一个队伍有一个做出题目的概率,求做出k个题目的概率.简单的简单的组合数DP.想清楚即可. 1: #include <iostream> 2: #include <cs ...
- 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 ...
- 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 ...
- Check the difficulty of problems
Check the difficulty of problems Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 5830 Acc ...
随机推荐
- 2018.1.9 博客迁移至csdn
http://blog.csdn.net/liyuhui195134?ref=toolbar
- [Webpack] Detect Unused Code with Webpack and unused-files-webpack-plugin
As you refactor and modify applications, it's difficult to manage and keep track of files as they be ...
- [Algorithm] Find Max Items and Max Height of a Completely Balanced Binary Tree
A balanced binary tree is something that is used very commonly in analysis of computer science algor ...
- 云计算之路-试用Azure:搭建自己的内网DNS服务器
之前我们写过一篇博文谈到Azure内置的内网DNS服务器不能跨Cloud Service,而我们的虚拟机部署场景恰恰需要跨多个Cloud Service,所以目前只能选择用Azure虚拟机搭建自己的内 ...
- LR打不开浏览器的解决方法
很久没用LoadRunner了,今天想复习一下,免得技能生疏,安装了一个LR11,跑一下,竟然打不开IE浏览器: 这时肯定是靠谷哥跟度娘的,经过一轮搜索,可以解决打开IE了,但录制不了解决,又 ...
- 使用VisualSVN建立SVN服务器
原地址:http://blog.csdn.net/happyjiang2009/article/details/5719988 以前使用官方Subversion搭建SVN版本控制环境,感觉很繁琐,需要 ...
- Struts2的国际化入门
Struts2的国际化入门 Struts2国际化是建立在Java国际化的基础上的,一样是通过提供不同国家/语言环境的消息资源,然后通过ResourceBundle加载指定Locale对应的资源文件,再 ...
- 【TP3.2】Call to a member function display() on a non-object问题的解决
Call to a member function display() on a non-object问题的解决
- PHP 导出 CSV 文件用 Excel 打开出现中文乱码
本篇文章由:http://xinpure.com/php-export-csv-file-opened-by-excel-appear-garbled/ 乱码情况 写了一段导出 CSV 文件的代码,可 ...
- linux系统常用命令 -设置文件夹读写权限
设置文件夹的读写权限: sudo chmod -R 777 /data 权限码描述 sudo chmod 600 ××× (只有所有者有读和写的权限)sudo chmod 644 ××× (所有者有读 ...