POJ 2151.Check the difficulty of problems
来源:互联网 发布:童装淘宝店简介怎么写 编辑:程序博客网 时间:2024/06/08 04:39
题目:http://poj.org/problem?id=2151
AC代码(C++):
#include <iostream>#include <algorithm>#include <stdio.h>#include <vector>#include <queue>#include <math.h>#include <string>#include <string.h>#include <bitset>#define INF 0xfffffff#define MAXN 100005#define prime 99991using namespace std;int m,t,n;double x[35][1005];double p[35];int main(){while(cin>>m>>t>>n){if(m==0)break;double p1 = 1, p2 = 1;for(int i = 0; i < t; i++){double p1i = 1;for(int j = 0; j < m; j++){cin>>p[j];p1i*=(1-p[j]);}p1*=(1-p1i);memset(x,0,sizeof(x));x[0][0] = 1;double p2i = 0;for(int j = 1; j <= m; j++){x[j][0] = x[j-1][0] * (1-p[j-1]);for(int k = 1; k <= n-1; k++)x[j][k] = x[j-1][k-1]*p[j-1] + x[j-1][k]*(1-p[j-1]);}for(int j = 1; j <= n-1; j++)p2i += x[m][j];p2*=p2i;}printf("%.3lf\n",p1-p2);}}总结: 动态规划问题. 问题求所有队伍做出至少1题且存在队伍做出至少n道题, 即求所有队伍做出至少一道题的概率p1减去所有队伍做出的题的数目都在[1,n-1]内的概率p2(也可以不包括1来直接求出答案). 用动态规划来描述就是, 某队伍在前j道题做出k道的概率为x[j][k] = x[j-1][k-1]*p[j] + x[j-1][k]*(1 - p[j]). 初始化时x数组第0行除了第0列外全赋值为0, x[0][0]为1. 逐行计算, 每行第0列可直接求出. 直到求出x[m][n-1].
阅读全文
0 0
- POJ 2151.Check the difficulty of problems
- poj 2151 Check the difficulty of problems
- POJ 2151 Check the difficulty of problems
- poj 2151 Check the difficulty of problems
- poj 2151 Check the difficulty of problems
- POJ 2151 Check the difficulty of problems
- POJ 2151 Check the difficulty of problems
- poj 2151 Check the difficulty of problems
- poj 2151 Check the difficulty of problems
- POJ 2151 Check the difficulty of problems
- POJ 2151 Check the difficulty of problems
- poj 2151 Check the difficulty of problems
- POJ 2151 Check the difficulty of problems
- 【POJ 2151】Check the difficulty of problems
- Check the difficulty of problems POJ 2151
- POJ 2151 Check the difficulty of problems
- POJ-2151 Check the difficulty of problems
- POJ 2151 Check the difficulty of problems
- .net MVC 随笔4
- 20171108Link
- Hive 之 内部表和外部表区别
- is和==的区别
- 游戏场景概念设计教程之构图技巧讲解
- POJ 2151.Check the difficulty of problems
- 自定义动态跳动的三个加载小点
- 关于Libevent的快速可移植非阻塞网络编程(block-》select-》poll-》epoll-》libevent)
- VS2015 tfs的使用教程
- mac安装mysql的两种方法(含配置)
- 什么双机热备? 为什么要做双机热备? 双机热备有哪几种?
- UITableView 卡顿、掉帧、的优化。cell里面循环创建view 导致卡顿掉帧的优化
- 2017CCPC秦皇岛
- kafka集群的安装及简单测试