• linkedu视频
  • 平面设计
  • 电脑入门
  • 操作系统
  • 办公应用
  • 电脑硬件
  • 动画设计
  • 3D设计
  • 网页设计
  • CAD设计
  • 影音处理
  • 数据库
  • 程序设计
  • 认证考试
  • 信息管理
  • 信息安全
菜单
linkedu.com
  • 网页制作
  • 数据库
  • 程序设计
  • 操作系统
  • CMS教程
  • 游戏攻略
  • 脚本语言
  • 平面设计
  • 软件教程
  • 网络安全
  • 电脑知识
  • 服务器
  • 视频教程
  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号
您的位置:首页 > 程序设计 >C语言 > POJ2151 Check the difficulty of problems 概率DP

POJ2151 Check the difficulty of problems 概率DP

作者:Gorden的博客 字体:[增加 减小] 来源:互联网 时间:2017-08-27

Gorden的博客通过本文主要向大家介绍了poj,dp,数学等相关知识,希望对您有所帮助,也希望大家支持linkedu.com www.linkedu.com

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:
- All of the teams solve at least one problem.
- 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 <= i <= T, 1<= j <= M). Well, can you calculate the probability that all of the teams solve at least one problem, and at the same time the champion team solves at least N problems?

  • 题意
    有M题的概率。

  • 解析
    涉及到 至少 这个词,不妨使用一些前缀和技巧。
    假设p1。
    我们需要分别计算每一队的贡献,再把相应的答案乘起来从而计算p1。
    设f[i][j]道题的概率。不难发现转移方程为
    再利用sum[i]道题的概率,其实就是前缀和。
    那么这个队对于p1。

  • 数组可以滚,你不滚也没关系

#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <map>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <algorithm>
#include <cctype>
#include <string>
using namespace std ;
const int maxn = 1005, maxm = 35 ;
int n, m, e ;
double p[maxm], f[2][maxm], sum[maxm] ;
int main() {
    int i, j, k ;
    while ( scanf ( "%d %d %d", &m, &n, &e ) != EOF ) {
        if ( !n ) break ;
        double p1 = 1.0, p2 = 1.0 ;
        for ( i = 1 ; i <= n ; i ++ ) {
            for ( j = 1 ; j <= m ; j ++ )
                scanf ( "%lf", &p[j] ) ;
            memset ( f, 0.0, sizeof f ) ;
            int u, v ;
            u = 0, v = 1 ;
            memset ( f, 0.0, sizeof f ) ;
            f[0][0] = 1.0 ;
            for ( j = 1 ; j <= m ; j ++, swap(u, v) )
                for ( k = 0 ; k <= j ; k ++ )
                    f[v][k] = f[u][k-1]*p[j]+f[u][k]*(1-p[j]) ;
            sum[0] = f[u][0] ;
            for ( j = 1 ; j <= m ; j ++ )
                sum[j] = sum[j-1]+f[u][j] ;
            p1 *= sum[m]-sum[0] ;
            p2 *= sum[e-1]-sum[0] ;
        }
        printf ( "%.3lf\n", p1-p2 ) ;
    }
    return 0 ;
}
分享到:QQ空间新浪微博腾讯微博微信百度贴吧QQ好友复制网址打印

您可能想查找下面的文章:

  • POJ2151 Check the difficulty of problems 概率DP

相关文章

  • 2017-05-28C++数据结构与算法之判断一个链表是否为回文结构的方法
  • 2017-05-285分钟内了解C语言的指针
  • 2017-05-28C语言实现二叉树遍历的迭代算法
  • 2017-05-28可读可执行的C语言简历源文件
  • 2017-05-28VC++中HTControl控制类使用之CHTDlgBase对话框基类实例
  • 2017-05-28详解C++的模板中typename关键字的用法
  • 2017-05-28深入理解void以及void指针的含义
  • 2017-05-28C语言中的abs()函数和exp()函数的用法
  • 2017-05-28C++动态分配和撤销内存以及结构体类型作为函数参数
  • 2017-05-28Cocos2d-x 3.x入门教程(一):基础概念

文章分类

  • JavaScript
  • ASP.NET
  • PHP
  • 正则表达式
  • AJAX
  • JSP
  • ASP
  • Flex
  • XML
  • 编程技巧
  • Android
  • swift
  • C#教程
  • vb
  • vb.net
  • C语言
  • Java
  • Delphi
  • 易语言
  • vc/mfc
  • 嵌入式开发
  • 游戏开发
  • ios
  • 编程问答
  • 汇编语言
  • 微信小程序
  • 数据结构
  • OpenGL
  • 架构设计
  • qt
  • 微信公众号

最近更新的内容

    • 对一个数组进行zig-zag重新排列
    • 深入理解C++的对象模型
    • c++读取sqlserver示例分享
    • C语言 函数指针(指向函数的指针)详解
    • C++中引用(&)的用法与应用实例分析
    • C++中对象的赋值与复制操作详细解析
    • 二分查找算法在C/C++程序中的应用示例
    • 深入解析C++编程中的纯虚函数和抽象类
    • 关于C语言程序的内存分配的入门知识学习
    • 数据结构之红黑树详解

关于我们 - 联系我们 - 免责声明 - 网站地图

©2020-2025 All Rights Reserved. linkedu.com 版权所有