POJ 2151 Check the difficulty of problems 概率dp+01背包
题目链接:
http://poj.org/problem?id=2151
Check the difficulty of problems
Time Limit: 2000MSMemory Limit: 65536K
#### 问题描述
> Organizing a programming contest is not an easy job. To avoid making the problems too difficult, the organizer usually expect the contest result satisfy the following two terms:
> 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
#### 输入
> The input consists of several test cases. The first line of each test case contains three integers M (0 输出
For each test case, please output the answer in a separate line. The result should be rounded to three digits after the decimal point.
样例输入
2 2 2
0.9 0.9
1 0.9
0 0 0
样例输出
0.972
题意
acm竞赛总共有m道题,t个队伍,并且知道第i个队伍做出第j道题的概率,求保证每个队伍都至少做出一道题,并且冠军队伍至少做出n道题的概率。
题解
原问题可以转换为求:所有的队伍都至少做出一题的概率-每个队伍都做出(1~n-1)道题的总概率。
代码
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<stack>
#include<ctime>
#include<vector>
#include<cstdio>
#include<string>
#include<bitset>
#include<cstdlib>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<functional>
using namespace std;
#define X first
#define Y second
#define mkp make_pair
#define lson (o<<1)
#define rson ((o<<1)|1)
#define mid (l+(r-l)/2)
#define sz() size()
#define pb(v) push_back(v)
#define all(o) (o).begin(),(o).end()
#define clr(a,v) memset(a,v,sizeof(a))
#define bug(a) cout<<#a<<" = "<<a<<endl
#define rep(i,a,b) for(int i=a;i<(b);i++)
#define scf scanf
#define prf printf
typedef __int64 LL;
typedef vector<int> VI;
typedef pair<int,int> PII;
typedef vector<pair<int,int> > VPII;
const int INF=0x3f3f3f3f;
const LL INFL=0x3f3f3f3f3f3f3f3fLL;
const double eps=1e-9;
const double PI = acos(-1.0);
//start----------------------------------------------------------------------
const int maxn=3333;
const int maxm=33;
///n个队伍,m道题,冠军至少做mm道。
int n,m,mm;
double dp[maxn][maxm];
double dp2[maxm][maxm];
double mat[maxn][maxm];
void init(){
clr(dp,0);
}
int main() {
while(scf("%d%d%d",&m,&n,&mm)==3&&n){
init();
for(int i=1;i<=n;i++){
clr(dp2,0);
///01背包,dp2[j][k],求第i个队伍前j道题做出k道的概率。
dp2[0][0]=1.0;
for(int j=1;j<=m;j++){
double x; scf("%lf",&x);
for(int k=0;k<=j;k++){
dp2[j][k]+=dp2[j-1][k]*(1-x);
if(k) dp2[j][k]+=dp2[j-1][k-1]*x;
}
}
///mat[i][k]:第i个队伍m道题做出k道的概率。
for(int k=0;k<=mm-1;k++) mat[i][k]=dp2[m][k];
}
///biger:所有的队伍都至少做出一题的概率
double biger=1.0;
for(int i=1;i<=n;i++) biger*=(1-mat[i][0]);
///dp[i][j]:统计前i个队伍中第i个队伍做了j题的总概率。
clr(dp,0);
for(int j=1;j<=mm-1;j++) dp[1][j]=mat[1][j];
for(int i=2;i<=n;i++){
for(int j=1;j<=mm-1;j++){
for(int k=1;k<=mm-1;k++){
dp[i][j]+=dp[i-1][k]*mat[i][j];
}
}
}
///sum:每个队伍都做出(1~mm-1)道题的总概率
double sum=0;
for(int i=1;i<=mm-1;i++) sum+=dp[n][i];
prf("%.3f\n",biger-sum);
}
return 0;
}
//end-----------------------------------------------------------------------
POJ 2151 Check the difficulty of problems 概率dp+01背包的更多相关文章
- [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 ...
随机推荐
- Linux入门基础(一):Linux基本操作
命令行BASH基本操作 Shell 用户不能直接操作内核,所以用户操作通过shell传递给内核 shell分为两种 : GUI 图形界面 (linux一般是GNOME) CLI 命令行界面 (linu ...
- 关于在MySql的decimal中犯的一个错-此篇文章目的在于警醒自己
今天在运行一段程序的时候报了Out of range value错误,网上的解释是说这个值与数据库字段类型不匹配,然而程序里面设置的是BigDecimal,数据库设置的是decimal,没有多想就把s ...
- Verilog 奇数分频
代码: module odd_div( ); ; //分频系数,3即3分频 ; reg clk, rstn, clk_div_pos, clk_div_neg; wire clk_div_out; : ...
- WPF中使用WindowChrome美化窗口过程中的一个小问题
WPF中使用WindowChrome美化窗口,在园子里有几篇不错的文章,我也是参考练习过程中发现的问题,并记录下来. 在看过几篇教程后,给出的窗口很多出现这样一个问题,如果设置了窗口标题栏的高度大于默 ...
- python基础学习1-三元表达式和lambda表达式
#!/usr/bin/env python # -*- coding:utf-8 -*- 三元运算 if else 的简写 name ="alex" if 1==1 else &q ...
- Kubernetes学习之路(十二)之Pod控制器--ReplicaSet、Deployment
一.Pod控制器及其功用 Pod控制器是用于实现管理pod的中间层,确保pod资源符合预期的状态,pod的资源出现故障时,会尝试 进行重启,当根据重启策略无效,则会重新新建pod的资源. pod控制器 ...
- 无聊中,写个常见的图片保护分类-iOS
当美工给出例如下面这种图的时候,但是需要拉伸的时候,就不得不做拉伸保护了. //调用代码 UIImage * img = [UIImage protectedImageWithLocalImageNa ...
- TMS320VC5509驱动TLV32AIC23
1. 本次使用LINE_IN作为输入,LINE_OUT作为输出(可以插耳机),代码如下,代码经过测试,没问题,不过发现了一个很奇怪的问题没搞明白 /************************** ...
- [FJOI2015]火星商店问题
[FJOI2015]火星商店问题 神仙线段树分治...不过我不会. 这题用线段树套可持久化Trie还是能写的. 常数有点大,洛谷垫底水平. // luogu-judger-enable-o2 #inc ...
- (webapp)微信和safri 对于html5 部分功能不兼容,多选或单选下拉框去除边框无效果。
1 appearance:none; 2 -moz-appearance:none; /* Firefox */ 3 -webkit-appearance:none; /* Safari 和 Chro ...