POJ 2151 Check the difficulty of problems (概率DP)
来源:互联网 发布:sai软件中文版 编辑:程序博客网 时间:2024/05/19 19:58
问题的解等于(所有队都做出至少一题的概率 - 所有队做题数都在1到N-1之间的概率)
设计DP状态时,因为DP过程中要记录哪些题做过了很难,一般来说要把DP的过程设计成有方向的,比如有一维表示前i个XX这种。
dp[i][j][k]表示第i队前j题做出k个的概率,dp方程就是dp[i][j][k]=dp[i][j-1][k-1]*acr[i][j]+dp[i][j-1][k]*(1-acr[i][j])
初始化dp[i][0][0]为1,dp[i][j][0]都设为相应情况所有题全错的概率。
代码:
#include <iostream>#include <cstdio>#include <cstring>using namespace std;#define LL long longdouble dp[1005][35][35];double acr[1005][35];int M,T,N;int main(){while(~scanf("%d%d%d",&M,&T,&N)){if(!M&&!T&&!N) break;for(int i=0;i<T;i++){for(int j=1;j<=M;j++){scanf("%lf",&acr[i][j]);}}for(int i=0;i<T;i++){dp[i][0][0]=1;for(int j=1;j<=M;j++){dp[i][j][0]=dp[i][j-1][0]*(1-acr[i][j]);}}for(int i=0;i<T;i++){for(int j=1;j<=M;j++){for(int k=1;k<=j;k++){dp[i][j][k]=dp[i][j-1][k-1]*acr[i][j]+dp[i][j-1][k]*(1-acr[i][j]);}}}double tot=1;double sub=1;for(int i=0;i<T;i++){double cur=0;for(int j=1;j<=M;j++){cur+=dp[i][M][j];}tot*=cur;cur=0;for(int j=1;j<N;j++){cur+=dp[i][M][j];}sub*=cur;}printf("%.3f\n",tot-sub);}return 0;}
0 0
- POJ 2151 Check the difficulty of problems(概率DP)
- POJ 2151 Check the difficulty of problems (概率dp)
- poj 2151 Check the difficulty of problems (概率DP)
- POJ 2151 Check the difficulty of problems(概率dp)
- POJ 2151 Check the difficulty of problems(概率dp)
- poj 2151 Check the difficulty of problems(概率dp)
- POJ 2151 Check the difficulty of problems (概率DP)
- Poj 2151 Check the difficulty of problems (概率DP)
- POJ 2151 Check the difficulty of problems(概率DP)
- poj 2151 Check the difficulty of problems(概率dp)
- POJ 2151 Check the difficulty of problems (概率DP)
- POJ 2151 Check the difficulty of problems(概率DP)
- POJ 2151 Check the difficulty of problems 概率DP
- poj 2151 Check the difficulty of problems 概率dp
- POj 2151 Check the difficulty of problems 概率DP
- 概率dp POJ 2151 Check the difficulty of problems
- poj 2151 Check the difficulty of problems(概率dp)
- poj 2151 Check the difficulty of problems(概率dp)
- 业务类型数据表
- MFC对进程权限的提升
- sysdba不能远程登录,我们该怎么做
- 感染性的木马病毒分析之样本KWSUpreport.exe
- Unity3D事件函数的执行顺序
- POJ 2151 Check the difficulty of problems (概率DP)
- android事件如何分发给子view
- mini2440系统移植篇之kernel启动流程
- PHP3.2配置文件使ini文件配置
- 第十二周程序阅读5
- STM32频率计算——捕获方式
- centos7 下Apache服务器配置
- 用java开发学生信息管理系统(SIMS,三)
- 2015年百度测试开发实习生面试