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 ...
随机推荐
- 关于mysql运行效率优化注意事项及要点
1. SQL优化的原则是:将一次操作须要读取的BLOCK数减到最低,即在最短的时间达到最大的数据吞吐量. 调整不良SQL通常能够从下面几点切入: ? 检查不良的SQL,考虑其写法是否还有可优化内容 ? ...
- Swift - 设置应用程序图标的提醒个数(右上角小红圈)
使用UILocalNotification除了可以实现本地消息的推送功能(可以设置推送内容,推送时间,提示音),还可以设置应用程序右上角的提醒个数. 下面演示如何设置,效果图如下: --- AppDe ...
- javascript 中 事件流和事件冒泡
一.事件流 是描述页面接受事件的顺序,IE 使用的是时间冒泡流;而Netscape的事件采用的是事件捕获流.1.事件冒泡JS 和 HTML是通过事件的方式实现交互.事件冒泡 开始元素,将事件逐级传递, ...
- ABAP常用字符串处理
1.SEARCH搜索指定字符串 REPORT Z_CHAR. ). MOVE 'Welcom to sap world!' to str. SEARCH str for 'sap'. 如果查找成功sy ...
- iTextSharp使用字体设置摘录
用iTextSharp做pdf转换的时候,需要添加水印.文字水印的时候,需要设置字体,查了下文档.摘录下解决方案. iText中输出中文,有三种方式: 1.使用iTextAsian.jar中的字体 ...
- Python Unittest 自动化单元测试框架Demo
python 测试框架(本文只涉及 PyUnit) https://wiki.python.org/moin/PythonTestingToolsTaxonomy 环境准备 首先确定已经安装有Pyth ...
- Ubuntu_开启root 登陆
默认的安装完ubuntu ,root 用户没有开启 1.使用安装时的用户,先给root用户设置密码 设置root密码 sudo passwd root 之后会提示输入新的密码 切换到root用户 su ...
- JAVA Useful Program(1)
public static void main(String[] args){ //字符串有整型的相互转换 String str=String.valueOf(123); ...
- HTTPClient和URLConnection核心区别分析
首先:在 JDK 的 java.net 包中已经提供了访问 HTTP 协议的基本功能:HttpURLConnection.但是对于大部分应用程序来说,JDK 库本身提供的功能还不够丰富和灵活. 在An ...
- 初识JAVA,对servlet的理解
一.WEB开发的简单理解 Web开发是一个指代网页或站点编写过程的广义术语.网页使用 HTML.CSS 和 JavaScript编写.这些页面可能是类似于文档的简单文本和图形.页面也能够是交互式的,或 ...