【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<=1000, M<=30)
#include <cstdio>
#include <cstring>
using namespace std;
const int T=1005, M=35;
double d[T][M], p[T][M];
int n, m, N;
void clr() {
for(int i=1; i<=n; ++i) for(int j=1; j<=m; ++j) d[i][j]=0;
}
int main() {
while(scanf("%d%d%d", &m, &n, &N), !(m==0&&n==0&&N==0)) {
for(int i=1; i<=n; ++i) for(int j=1; j<=m; ++j) scanf("%lf", &p[i][j]);
for(int i=1; i<=n; ++i) d[i][0]=1;
for(int i=1; i<=n; ++i)
for(int k=1; k<=m; d[i][0]*=1-p[i][k], ++k)
for(int j=m; j; --j) d[i][j]=d[i][j]*(1-p[i][k])+d[i][j-1]*p[i][k];
//for(int i=1; i<=n; ++i) { for(int j=0; j<=m; ++j) printf("%.2f ", d[i][j]); puts(""); }
for(int i=1; i<=n; ++i) for(int j=m; j; --j) d[i][j]+=d[i][j+1];
double ans=0, sum;
for(int i=1; i<=n; ++i) {
sum=d[i][N];
for(int j=1; j<i; ++j) sum*=(d[j][1]-d[j][N]);
for(int j=i+1; j<=n; ++j) sum*=d[j][1];
ans+=sum;
}
printf("%.3f\n", ans);
clr();
}
return 0;
}
我们只需要设状态就行了= =随便搞...
设f[i][j][k]表示第i队解决j~k个问题的概率
$$ans=\sum_{i} \left( f[i][N][M] * \prod_{j<i} f[j][1][N-1] * \prod_{j>i} f[j][1][M] \right) $$
这样就能不重不漏....(不难理解,我觉得这个很简单的吧= =
然后我们来一发前缀和,d[i][j]表示第i队解决至少j个问题的概率
$$ans=\sum_{i} \left( d[i][N] * \prod_{j<i} ( d[j][1]-d[j][N] ) * \prod_{j>i} d[j][1] \right) $$
问题转化为如何求d[i][j]...
设d'[i][j]表示第i队解决j个问题的概率
我们类似背包依次加入每个问题,有
d[i][j]=d[i][j]*(1-p[i][k])+d[i][j-1]*p[i][k](自己好好思考= =,我拐了好多个弯才想出来QAQ
于是就ok了。。。
【POJ】2151 Check the difficulty of problems的更多相关文章
- 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 ...
- 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)
Check the difficulty of problems Time Limit: 2000MS Memory Limit: 65536K Total Submissions: 4522 ...
- [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【至少】
题目链接:http://poj.org/problem?id=2151 题意: 一次ACM比赛,有t支队伍,比赛共m道题. 第i支队伍做出第j道题的概率为p[i][j]. 问你所有队伍都至少做出一道, ...
- 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)
题意:ACM比赛中,共M道题,T个队,pij表示第i队解出第j题的概率 ,求每队至少解出一题且冠军队至少解出N道题的概率. 析:概率DP,dp[i][j][k] 表示第 i 个队伍,前 j 个题,解出 ...
- POJ 2151 Check the difficulty of problems (概率dp)
题意:给出m.t.n,接着给出t行m列,表示第i个队伍解决第j题的概率. 现在让你求:每个队伍都至少解出1题,且解出题目最多的队伍至少要解出n道题的概率是多少? 思路:求补集. 即所有队伍都解出题目的 ...
随机推荐
- Delphi面向对象的属性
可以把属性看成是能对类中的数据进行修改和执行代码的特殊的辅助域.对于组件来说,属性就是列在Object Inspector窗口的内容.下面的例子定义了一个有属性的简单对象 TMyObject = cl ...
- 【20140113-2】MyEclipse生成javadoc时出错:编码GBK的不可映射字符
今天生成java doc文档时,出现了如下所示的错误: 正在装入软件包 com.wisdom.test 的源文件...F:\workspace\StringUtils\src\com\wisdom\t ...
- jq与js 区别
$(this).html(666); <div id="a">123</div> <script> $("#a").clic ...
- js this的使用举例
js this的使用举例 <script type="text/javascript"> function test(obj){ obj.style.width= ob ...
- wpf template的code写法
this.Template = XamlReader.Load ("<ControlTemplate xmlns='http://schemas.microsoft.com/clien ...
- 剑指offer系列——二维数组中,每行从左到右递增,每列从上到下递增,设计算法找其中的一个数
题目:二维数组中,每行从左到右递增,每列从上到下递增,设计一个算法,找其中的一个数 分析: 二维数组这里把它看作一个矩形结构,如图所示: 1 2 8 2 4 9 12 4 7 10 13 6 8 11 ...
- Vue#计算属性
在模板中表达式非常便利,但是它们实际上只用于简单的操作.模板是为了描述视图的结构.在模板中放入太多的逻辑会让模板过重且难以维护.这就是为什么 Vue.js 将绑定表达式限制为一个表达式.如果需要多于一 ...
- 【J2EE入门】13个规范
看过了j2ee教学视频,真的让我痛彻心扉,那叫痛并快乐着,痛是因为看了这么长时间,自己只知道了13个规范的概念:同样,快乐也正是因为我知道了13个规范的概念,接下来就是逐项实践的学习. 看了教学视频, ...
- js循环添加事件
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...
- bat
1.输出系统时间,利用系统时间做文件名 @echo offset filename=%date:~0,4%%date:~5,2%%date:~8,2%%time:~0,2%%time:~3,2%%ti ...