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 ...
随机推荐
- os.waitpid()无法获取sys.exit()退出时的status code
[目的] 父进程使用os.waitpid()等待子进程退出,并检测子进程的exit code,以决定是否重启子进程. (常见的应用场景是:子进程接收外部命令,收到"stop"时退出 ...
- 转:关于腾讯bugly崩溃的android so符号表使用
http://www.jikexueyuan.com/course/406_8.html
- [Functional Programming ADT] Create a Redux Store for Use with a State ADT Based Reducer
With a well defined demarcation point between Redux and our State ADT based model, hooking up to a R ...
- Flutter常用布局组件
Flutter控件本身通常由许多小型.单用途的控件组成,结合起来产生强大的效果,例如,Container是一种常用的控件,由负责布局.绘画.定位和大小调整的几个控件组成,具体来说,Container是 ...
- angular 事件广播和事件监听
一,angularjs $broadcast $emit $on的处理思想 在一个controller里面通过事件触发一个方法,在方法里面通过$broadcast或$emit来定义一个变量,在父,子c ...
- python基础教程_学习笔记12:充电时刻——模块
充电时刻--模块 python的标准安装包含一组模块,称为标准库. 模块 >>> import math >>> math.sin(0) 0.0 模块是程序 不论什 ...
- hibernate 一对多关联
package com.bjsxt.hibernate; import java.util.HashSet; import java.util.Set; import javax.persistenc ...
- Firefly 3288又一次制作android和lubuntu双系统固件
又一次制作android和lubuntu双系统固件 因为本人改动了lubuntu的驱动和设备树信息,为了方便烧写系统,所以又一次制作了双系统的固件. Firefly wiki教程里有android固件 ...
- 设置右上角的菜单button
效果如图: 刚開始是单独做了个button.发现无法调margin,后来想到外面套一个布局 <?xml version="1.0" encoding="utf-8& ...
- navigate是Router类的一个方法,主要用来跳转路由。
navigate是Router类的一个方法,主要用来跳转路由. 1 2 3 4 5 6 7 8 9 interface NavigationExtras { relativeTo : Activat ...