惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

量子位
WordPress大学
WordPress大学
小众软件
小众软件
云风的 BLOG
云风的 BLOG
IT之家
IT之家
人人都是产品经理
人人都是产品经理
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
Last Week in AI
Last Week in AI
博客园 - 【当耐特】
T
Tailwind CSS Blog
阮一峰的网络日志
阮一峰的网络日志
V
V2EX
宝玉的分享
宝玉的分享
博客园 - Franky
F
Fortinet All Blogs
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
GbyAI
GbyAI
Hugging Face - Blog
Hugging Face - Blog
Jina AI
Jina AI
D
Docker
博客园 - 聂微东
C
Check Point Blog
H
Help Net Security

OhYee 博客

小鹏辅助驾驶测评|OhYee 博客 小鹏非支持手机开启自动解锁|OhYee 博客 使用函数计算实现 301 重定向|OhYee 博客 针对 HTML 内容使用 Ant Design 图片弹框|OhYee 博客 博客进程泄露及僵尸进程解决|OhYee 博客 蓝易云服务器体验|OhYee 博客 SSH 调起本地 VSCode|OhYee 博客 【2022 秋招内推】阿里云后端研发工程师|OhYee 博客 使用函数计算获取 IP 地址信息|OhYee 博客 正确获取客户端 IP/HTTP Header 也可能重复|OhYee 博客 评测 Oculus Quest2 及 BigScreen|OhYee 博客 NextJS 热重载保留状态|OhYee 博客 如何优雅地贴 gist 代码|OhYee 博客 Linux 精细化文件权限|OhYee 博客 VSCode 容器开发环境|OhYee 博客 Clash 的不兼容更新排查|OhYee 博客 Zeek 导出 PCAP|OhYee 博客 记一次 ssh 配置问题|OhYee 博客 Git Commit 规范化工具|OhYee 博客 谈谈《星之卡比-探索发现》|OhYee 博客 VSCode 快捷键绑定 Shell 命令|OhYee 博客 ASN.1 语法及 X.509 证书格式解析解析|OhYee 博客 腾讯企业邮箱忽略 MX 记录发信|OhYee 博客 Chrome/Edge 标签组插件|OhYee 博客 【应届内推】阿里云后端研发工程师|OhYee 博客 损坏的 Typecho 备份处理为 JSON|OhYee 博客 VS Code VIM 插件高效使用|OhYee 博客 SSH 正反向代理|OhYee 博客 Let's Encrypt 根证书过期引发的问题|OhYee 博客 OpenWRT 忽略内核依赖|OhYee 博客
POJ 2151.Check the difficulty of problems|OhYee 博客
2017-08-05 · via OhYee 博客

这是一篇最后编辑于 8 年前 的文章,其内容可能与目前实际情况差异较大,请注意甄别

题目

{% fold 点击显/隐题目 %}

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 <= 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?

The input consists of several test cases. The first line of each test case contains three integers M (0 < M <= 30), T (1 < T <= 1000) and N (0 < N <= M). Each of the following T lines contains M floating-point numbers in the range of [0,1]. In these T lines, the j-th number in the i-th line is just Pij. A test case of M = T = N = 0 indicates the end of input, and should not be processed.

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

{% endfold %}

题解

dp[i][j][k] 表示第i个队伍在前j道题中做出k题

有递推式
dp[i][j][k] += dp[i][j - 1][k - 1] * Prob[i][j] + dp[i][j - 1][k] * (1 - Prob[i][j])

计算出来后,需要用概率的知识计算满足每一队都至少过一题,并且至少有一队过N题的概率

首先计算出所有队伍至少过一题的数量

代码

{% fold 点击显/隐代码 %}```cpp Check the difficulty of problems https://github.com/OhYee/sourcecode/tree/master/ACM 代码备份
#include
#include
#include
using namespace std;

const int maxT = 1005;
const int maxM = 35;

double Prob[maxT][maxM];
double dp[maxT][maxM][maxM];

int main() {
int M, T, N;
while (scanf("%d%d%d", &M, &T, &N) != EOF) {
if (!(M | T | N))
break;

    for (int i = 1; i <= T; ++i)
        for (int j = 1; j <= M; ++j)
            scanf("%lf", &Prob[i][j]);

    for (int i = 1; i <= T; ++i)
        dp[i][0][0] = 1.0;

    // dp[i][j][k] 第i个队伍在前j道题中做出k题
    for (int i = 1; i <= T; ++i)
        for (int j = 1; j <= M; ++j)
            for (int k = 0; k <= j; ++k) {
                dp[i][j][k] = 0.0;
                if (k != 0)
                    dp[i][j][k] += dp[i][j - 1][k - 1] * Prob[i][j];
                // if (k != j)
                dp[i][j][k] += dp[i][j - 1][k] * (1 - Prob[i][j]);
            }

    double P1 = 1.0; //有队伍达到N题
    double P2 = 1.0; //有队伍未达到1题
    for (int i = 1; i <= T; ++i) {
        double sum = 0.0;
        for (int j = 1; j < N; ++j)
            sum += dp[i][M][j];
        P1 *= sum;
        P2 *= 1 - dp[i][M][0];
    }
    // P1 = 1 - P1;
    // P2 = 1 - P2;

    // printf("%.3f\n", P1 - P2);
    cout << fixed << setprecision(3) << P2 - P1 << endl;
}
return 0;

}

{% endfold %}