POJ 2151 Check the difficulty of problems (动态规划-可能DP)
| Time Limit: 2000MS | Memory Limit: 65536K | |
| Total Submissions: 4522 | Accepted: 1993 |
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
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
Sample Input
2 2 2
0.9 0.9
1 0.9
0 0 0
Sample Output
0.972
Source
题目大意:
有 M 道题目 T 支队伍。N表示 最好 的队 至少要做出N题 ,紧接下来T行M列,表示某队做出某题 的概率为p ,问你每支队至少做出1题,最好的队至少做出N题的概率是多少?
解题思路:
一题动态规划的题。 既然最好的队至少做出N题。那么用二维记录,DP [t][f] 记录还剩 t 支队及是否出现超过N题的事件的概率。假设当前这支队伍做出超过N题,那么f置为1,否则还是f。弹了两遍,第一遍由于忘记算做出0题的情况,第二遍由于递归中数组开得略大些超内存了。
解题代码:
#include <iostream>
#include <cstdio>
using namespace std; const int maxt=1100;
const int maxn=32;
double dp[maxt][2];
double p[maxt][maxn]; int T,M,N; double DP(int t,int f){
if(t<=0) return f;
if(dp[t][f]>-1.0) return dp[t][f]; double a[maxn][maxn],ans=0;
a[0][0]=1;
for(int i=1;i<=M;i++){
for(int j=0;j<=i;j++){
a[i][j]=0;
if(j-1>=0) a[i][j]+=a[i-1][j-1]*p[t][i];
if(i-1>=j) a[i][j]+=a[i-1][j]*(1-p[t][i]);
}
}
for(int i=1;i<N;i++) ans+=DP(t-1,f)*a[M][i];
for(int i=N;i<=M;i++) ans+=DP(t-1,1)*a[M][i]; return dp[t][f]=ans;
} void input(){
for(int i=1;i<=T;i++){
dp[i][0]=dp[i][1]=-2.0;
for(int j=1;j<=M;j++){
scanf("%lf",&p[i][j]);
}
}
} void solve(){
printf("%.3f\n",DP(T,0));
} int main(){
while(scanf("%d%d%d",&M,&T,&N)!=EOF && (T||M||N) ){
input();
solve();
}
return 0;
}
版权声明:这篇文章的博客toyking原创文章。博客,未经同意不得转载。
POJ 2151 Check the difficulty of problems (动态规划-可能DP)的更多相关文章
- 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道题的概率是多少? 思路:求补集. 即所有队伍都解出题目的 ...
- 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 ...
- [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: 8903 ...
- 【POJ】2151 Check the difficulty of problems
http://poj.org/problem?id=2151 题意:T个队伍M条题目,给出每个队伍i的每题能ac的概率p[i][j],求所有队伍至少A掉1题且冠军至少A掉N题的概率(T<=100 ...
随机推荐
- Apache服务器学习笔记
Apache服务器知识 首先我们要知道一共有那几个程序在监听网络端口,即与网络保持活跃连接,打开CMD命令窗口 输入: netstat –an 指令就能显示出所有与网络保持连接的程序,输入net s ...
- ASP.NET - 记住滚动条的位置
MaintainScrollPositionOnPostback ="true" 如果是滚动条在最下面,那么如果刷新页面,滚动条回到最上面. 使用这个属性之后,滚动条会在刷新之前的 ...
- 两个栈实现队列+两个队列实现栈----java
两个栈实现队列+两个队列实现栈----java 一.两个栈实现一个队列 思路:所有元素进stack1,然后所有出s ...
- Re-installation failed due to different application signatures.
出现此问题是由于apk的签名不同所致(假设不知道签名是什么 请看上一篇Android应用程序签名 debug签名).假设你是使用的自己的签名,那就是你新版本号的apk使用的签名文件与上一版本号(也就 ...
- Swift - 使用下划线(_)来分隔数值中的数字
为了增强较大数值的可读性,Swift语言增加了下划线(_)来分隔数值中的数字. 不管是整数,还是浮点数,都可以使用下划线来分隔数字. 1 2 3 4 //数值可读性 let value1 = 10_0 ...
- C# - 重写虚方法
项目目录: 创建教师类(Teacher),虚方法有Teach(); 创建学生类(Student),重写的方法是Teach(); 教师类: · 加上关键字 Virtual 就是声明可以重写此方法. us ...
- Windows 8 动手实验系列教程 实验8:Windows应用商店API
动手实验 实验 8: Windows应用商店API 2012年9月 简介 编写Windows应用商店应用最令人瞩目的理由之一是您可以方便地将它们发布到Windows应用商店.考虑到世界范围内目前有超过 ...
- Vmdk文件如何使用,vmdk导入虚拟机VMware8.0教程
一.打开虚拟机VMware Workstation8.0,点击新建虚拟机. 二.进入虚拟机向导,选择自定义. 三.这里保持默认即可. 四.这里选择“我以后安装操作系统”. 五.这里选择Windows ...
- SQL server语句练习
相关表: <span style="white-space:pre">create table DEPT ( <span style="white-sp ...
- hdu 4714 Tree2cycle dp
用树形dp做的,dp[t][i]表示t及其孩子入度都已经小于等于2并且t这个节点的入度等于i的最优解. 那么转移什么的自己想想就能明白了. 关键在于这个题目会暴栈,所以我用了一次bfs搜索出节点的顺序 ...