POJ-2151 Check the difficulty of problems---概率DP好题
题目链接:
https://vjudge.net/problem/POJ-2151
题目大意:
ACM比赛中,共M道题,T个队,pij表示第i队解出第j题的概率
问 每队至少解出一题且冠军队至少解出N道题的概率。
解题思路:
看了题解才恍然大悟,还是做题少没思路。
要求:每队至少解出一题 且 冠军队至少解出N道题的概率
由于冠军队可以不止一队,即允许存在并列冠军
则原来的所求的概率可以转化为:
每队均至少做一题的概率P1 减去 每队做题数均在1到N-1之间的概率P2

注意初始条件,其他递推即可
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;
const int maxn = ;
double p[maxn][];//p[i][j]表示第i个队做出第j题的概率
double dp[maxn][][];//dp[i][j][k]表示第i个队前j道题做出k题的概率
double sum[maxn][];//sum[i][j]表示第i个队伍做出至多k题的概率(前缀和)
int main()
{
int n, m, t;
while(cin >> m >> t >> n && m)
{
for(int i = ; i <= t; i++)
{
for(int j = ; j <= m; j++)
cin >> p[i][j];
}
memset(dp, , sizeof(dp));
memset(sum, , sizeof(sum));
for(int i = ; i <= t; i++)
{
dp[i][][] = p[i][];
dp[i][][] = 1.0 - p[i][];
for(int j = ; j <= m; 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 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 p1 = , p2 = ;
//p1表示所有队伍至少做出1题的概率
//p2表示所有队伍做题数目在1-n-1之间
for(int i = ; i <= t; i++)
p1 *= (sum[i][m] - sum[i][]),
p2 *= (sum[i][n - ] - sum[i][]);
printf("%.3f\n", p1 - p2);
}
}
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 ...
随机推荐
- 需要了解的几个Java基础点
关键字 native:表示要调用非Java语言写函数,比如用C语言使用JNI实现的接口.比如windows环境的dll文件.举例:Object.hashcode() 位运算 << n:左移 ...
- Appium appium 基础之键盘处理
方法1 AppiumDriver实现了在上述功能,代码如下(java版本) driver.sendKeyEvent(66);方法2 HashMap keycode = new HashMap();ke ...
- Subarray Sum K
Given an nonnegative integer array, find a subarray where the sum of numbers is k. Your code should ...
- QQ号_保存_20180124
1.1337978907 (密码:33+我的名字全小写全部拼音) 2. 3. 4. 5.
- spring MVC设置不拦截静态资源
问题产生: 因为我们在web.xml中写了 拦截所有请求,当然包括了静态资源,所以页面需要引用css或js的话,该请求也会被拦截,例如: 在style.css中写一个简单样式,加个背景颜色 body ...
- c++ primer 中讲的顶层const 和 底层 const 理解
c++ primer 中讲的 顶层const 和 底层 const 以前没搞懂的顶层const和底层const,这次看了后感觉明白了. 首先,const是一个限定符,被它修饰的变量的值不能改 ...
- RTT设备与驱动之硬件定时器
硬件定时器可以对外部时钟进行计数,利用内部时钟进行定时. 函数 描述 rt_device_t rt_device_find(const char* name); 查找定时器设备 rt_err_t rt ...
- #1413 : Rikka with String 后缀自动机 + 二级差分
http://hihocoder.com/problemset/problem/1413?sid=1199641 这题断断续续做了2个多星期吧,一直不会 设总答案为sum,替换后新加的子串数量为x,失 ...
- UnityError SocketException: 以一种访问权限不允许的方式做了一个访问套接字的尝试。
SocketException: 以一种访问权限不允许的方式做了一个访问套接字的尝试. 以管理员身份运行Unity就可以了,权限不够的问题.
- php表单提交时的身份证号码验证
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/ ...