【poj2151】 Check the difficulty of problems
http://poj.org/problem?id=2151 (题目链接)
题意
T支队伍,一共M道题,第i支队伍解出第j道题的概率为p[i][j]。问每支队伍至少解出1道题并且解题最多的的队伍至少解出N道题的概率。
Solution
我终于明白了,这种题目,永远也不要想着去搞清楚样例是怎么算出来的,只要列出你认为正确的dp方程就行了。。
于是这道题,令${f_{i,j,k}}$表示第i个队伍,前j道题,解出k道的概率。转移很显然:
$${f_{i,j,k}=f_{i,j-1,k-1}*p_{i,j}+f_{i,j-1,k}*(1-p_{i,j})}$$
再令${s_{i,j}}$表示第i个队伍解出的题目数小于等于j道的概率,那么很显然:
$${s_{i,j}=s_{i,j-1}+f_{i,m,j}}$$
于是每个队伍解出的题目数再范围${1,M}$的概率p1(也就是至少解出一道题):
$${p1=\prod_{i=1}^{t}(1-s_{i,0})}$$
每个队伍解出的题目数在范围${1,N-1}$的概率p2(每个队伍都至少解出一道题,但没有一支队伍解题数大于等于N):
$${p2=\prod_{i=1}^{t}(s_{i,N-1}-s_{i,0})}$$
那么最后的答案:p1-p2
代码
// poj2151
#include<algorithm>
#include<iostream>
#include<cstdlib>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LL long long
#define inf 1<<30
#define eps 1e-8
#define Pi acos(-1.0)
#define free(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout);
using namespace std; const int maxt=1010,maxm=40;
double f[maxt][maxm][maxm],s[maxt][maxm],p[maxt][maxm];
int n,m,t; int main() {
while (scanf("%d%d%d",&m,&t,&n)!=EOF && m && t && n) {
memset(f,0,sizeof(f));
for (int i=1;i<=t;i++)
for (int j=1;j<=m;j++) scanf("%lf",&p[i][j]);
for (int i=1;i<=t;i++) {
f[i][0][0]=1;
for (int j=1;j<=m;j++)
for (int k=0;k<=j;k++) {
f[i][j][k]=f[i][j-1][k]*(1-p[i][j]);
if (k) f[i][j][k]+=f[i][j-1][k-1]*p[i][j];
}
s[i][0]=f[i][m][0];
for (int j=1;j<=m;j++) s[i][j]=s[i][j-1]+f[i][m][j];
}
double p1=1,p2=1;
for (int i=1;i<=t;i++) p1*=1-s[i][0],p2*=(s[i][n-1]-s[i][0]);
printf("%.3lf\n",p1-p2);
}
return 0;
}
【poj2151】 Check the difficulty of problems的更多相关文章
- 【POJ2151】Check the difficulty of problems
题意 某场比赛有M道问题,T支队伍,和数字N给出每支队伍解决每道问题的概率. 问这场比赛满足下面两个条件的概率 1.每支队伍至少做出一道题 2.冠军队至少做出N道题. 分析 条件2是不是可以转化为 至 ...
- 【POJ】【2151】Check the difficulty of problems
概率DP kuangbin总结中的第8题 一开始题目看错导致想转移方程想错了……想成f[i][j]表示前 i 个队伍中最多的做出来 j 道题的概率……sigh 看了下题解……其实是对于每个队伍 i 单 ...
- 【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
以前做过的题目了....补集+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 ...
- 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 Total Submissions: 4522 ...
- 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 ...
随机推荐
- 扩展JS Date对象时间格式化功能
在自己JS代码中引入一下代码: Date.prototype.format =function(format) { var o = { "M+" : this.getMonth() ...
- C#Excel文件加密实现,支持xlsx、docx、pptx(C#\Net\Asp.Net)
从此刻开始,我已封闭!概不接客! 像风一样的男人,像风一样的性格,无拘无束,不拘一格.那么问题来了,当风遇到沙,不一定你是风儿,我是沙儿的缠缠绵绵,.也许是漫天黄沙,飞粒走石.如果我们期望擒住这漫天的 ...
- iOS真机测试could not find developer disk image
兄弟你该升级xcode的了,xcode的版本已经落后于手机的iOS版本了
- 拥抱.NET Core,跨平台的轻量级RPC:Rabbit.Rpc
不久前发布了一篇博文".NET轻量级RPC框架:Rabbit.Rpc",当初只实现了非常简单的功能,也罗列了之后的计划,经过几天的不断努力又为Rabbit.Rpc增加了一大波新特性 ...
- 从零自学Hadoop(18):Hive的CLI和JDBC
阅读目录 序 Hive CLI(old CLI) Beeline CLI(new CLI) JDBC Demo下载 系列索引 本文版权归mephisto和博客园共有,欢迎转载,但须保留此段声明,并给出 ...
- Centos6.5安装mysql不能启动,应该安装mysql-server
centos中安装mysql很简单如下命令即可 yum install mysql 装好了, 运行mysql ERROR 2002 (HY000): Can't connect to local My ...
- 移动WEB像素相关知识
了解移动web像素的知识,主要是为了切图时心中有数.本文主要围绕一个问题:怎样根据设备厂商提供的屏幕尺寸和物理像素得到我们切图需要的逻辑像素?围绕这个问题以iphone5为例讲解涉及到的web像素相关 ...
- SQL必知必会 14-22(完)
博主依然不想打字,又向你仍来了一堆代码... 13(续) 在SELECT中用COUNT()以及联合 mysql> SELECT customers.cust_id,COUNT(orders.or ...
- React构建单页应用方法与实例
React作为目前最流行的前端框架之一,其受欢迎程度不容小觑,从这门框架上我们可以学到许多其他前端框架所缺失的东西,也是其创新性所在的地方,比如虚拟DOM.JSX等.那么接下来我们就来学习一下这门框架 ...
- BZOJ 3289: Mato的文件管理[莫队算法 树状数组]
3289: Mato的文件管理 Time Limit: 40 Sec Memory Limit: 128 MBSubmit: 2399 Solved: 988[Submit][Status][Di ...