这道题是这种,给主人公一堆事件的成功概率,他仅仅想恰好成功一件。

于是,问题来了,他要选择哪些事件去做,才干使他的想法实现的概率最大。

我的第一个想法是枚举,枚举的话我想到用dfs,但是认为太麻烦。

于是想是不是有什么规律,于是推导了一下,推了一个出来,写成代码提交之后发现是错的。

最后就没办法了,剩下的时间不够写dfs,于是就放弃了。

今天看thnkndblv的代码,代码非常短,于是就想肯定是有什么数学规律,于是看了一下,

果然如此。

是这种,还是枚举,当然是有技巧的,看我娓娓道来。

枚举的话,如果总共同拥有n件事件,

从中选择1件事情去做,实现的概率最大是多少,

选择2件事情去做,实现的概率最大是多少,以此类推到选择n件事情去做。

于是就会得到n个结果,里面最大的那个就是实现主人公想法的最大概率。

这种话要从n件事件中随意选出1件事情然后比概率,随意选出2件事情然后比概率……随意选出n件事情然后比概率

还是要搜索。

可是这里就有数学知识了,能够不用搜索,做法是这种:

将n个事件成功的概率从大到小排序,

然后,

仅仅选择前1件事去做成功的概率就是“从中选择1件事情去做,最大的实现概率”

仅仅选择前2件事去做成功的概率就是“从中选择2件事情去做,最大的实现概率”

以此类推。

有了这个,这道题就非常easy了,至于为什么这样做能够,无法证明,假设有人证明的话,欢迎留言讨论,附上原题以及地址和我后来AC的代码例如以下:

http://codeforces.com/contest/443/problem/D

D. Andrey and Problem
time limit per test

2 seconds

memory limit per test

256 megabytes

input

standard input

output

standard output

Andrey needs one more problem to conduct a programming contest. He has
n friends who are always willing to help. He can ask some of them to come up with a contest problem. Andrey knows one value for each of his fiends — the probability that this friend will come up with a problem if Andrey asks him.

Help Andrey choose people to ask. As he needs only one problem, Andrey is going to be really upset if no one comes up with a problem or if he gets more than one problem from his friends. You need to choose such a set of people that maximizes the chances
of Andrey not getting upset.

Input

The first line contains a single integer n
(1 ≤ n ≤ 100) — the number of Andrey's friends. The second line contains
n real numbers pi
(0.0 ≤ pi ≤ 1.0) — the probability that the
i-th friend can come up with a problem. The probabilities are given with at most 6 digits after decimal point.

Output

Print a single real number — the probability that Andrey won't get upset at the optimal choice of friends. The answer will be considered valid if it differs from the correct one by at most
10 - 9.

#include<iostream>
#include<algorithm>
using namespace std;
bool cmp(double a,double b)
{
return a>b;
}
int main()
{
int n,i,j,k;
double a[110],x,sum,MAX;
scanf("%d",&n);
for(i=0;i<n;i++)
scanf("%lf",&a[i]);
sort(a,a+n,cmp);
MAX=0;
for(i=1;i<=n;i++)
{
sum=0;
for(j=0;j<i;j++)
{
x=a[j];
for(k=0;k<i;k++)
{
if(j!=k)
x*=1-a[k];
}
sum+=x;
}
MAX=max(sum,MAX);
}
printf("%.12lf\n",MAX);
}

codeforces#253 D - Andrey and Problem里的数学知识的更多相关文章

  1. codeforces 442B B. Andrey and Problem(贪心)

    题目链接: B. Andrey and Problem time limit per test 2 seconds memory limit per test 256 megabytes input ...

  2. 【codeforces 442B】 Andrey and Problem

    http://codeforces.com/problemset/problem/442/B (题目链接) 题意 n个人,每个人有p[i]的概率出一道题.问如何选择其中s个人使得这些人正好只出1道题的 ...

  3. 【Codeforces 442B】Andrey and Problem

    [链接] 我是链接,点我呀:) [题意] n个朋友 第i个朋友帮你的概率是pi 现在问你恰好有一个朋友帮你的概率最大是多少 前提是你可以选择只问其中的某些朋友不用全问. [题解] 主要思路是逆向思维, ...

  4. Codeforces Round #253 (Div. 1) B. Andrey and Problem

    B. Andrey and Problem time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  5. Codeforces 442B Andrey and Problem(贪婪)

    题目链接:Codeforces 442B Andrey and Problem 题目大意:Andrey有一个问题,想要朋友们为自己出一道题,如今他有n个朋友.每一个朋友想出题目的概率为pi,可是他能够 ...

  6. cf442B Andrey and Problem

    B. Andrey and Problem time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  7. Andrey and Problem

    B. Andrey and Problem time limit per test 2 seconds memory limit per test 256 megabytes input standa ...

  8. QDUoj GZS的三角形 棋盘里的数学 思维+杨辉三角

    1. 题目 我的提交 GZS的三角形 发布时间: 2015年9月6日 15:18   最后更新: 2016年6月26日 12:10   时间限制: 1000ms   内存限制: 256M 描述 机智无 ...

  9. Codeforces Round #253 (Div. 2) D. Andrey and Problem

    关于证明可以参考题解http://codeforces.com/blog/entry/12739 就是将概率从大到小排序然后,然后从大到小计算概率 #include <iostream> ...

随机推荐

  1. HDU--杭电--3790--最短路径问题

    最短路径问题 Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others) Total Sub ...

  2. 认识axure组件区域

    组件区域也叫做部件区域,英文为widgets,还有人称之为控件区域,组件是axure事先准备好的网站项目常用的零件,比如一些基本的页面元素 Axure默认存在2个组件库,分别为线框图和流程图.同时我们 ...

  3. boost参考博客

    http://blog.csdn.net/caimouse/article/category/1339053

  4. 九度OnlineJudge之1018:统计同成绩学生人数

    题目描述: 读入N名学生的成绩,将获得某一给定分数的学生人数输出. 输入:                        测试输入包含若干测试用例,每个测试用例的格式为 第1行:N 第2行:N名学生的 ...

  5. Phalcon资源文件管理(Assets Management)

    资源文件管理(Assets Management)¶ Phalcon\Assets是一个让开发人员管理静态资源的组件,如管理css,javascript等. Phalcon\Assets\Manage ...

  6. python 下载整个站点

    用python实现的下载整个站点工具. 核心流程非常easy: 1. 输入站点地址 2. url.得到响应的内容. 3. 依据响应的http报文头,假设类型为html, 则从第4步開始运行. 假设是其 ...

  7. 高斯消元法~get√

    高斯消元法,是线性代数中的一个算法,可用来求解线性方程组,并可以求出矩阵的秩,以及求出可逆方阵的逆矩阵.高斯消元法的原理是:若用初等行变换将增广矩阵 化为 ,则AX = B与CX = D是同解方程组. ...

  8. 在ListCtrl控件中设置自定义光标

    ::SetCursor(::LoadCursor   (::AfxGetInstanceHandle(),   MAKEINTRESOURCE(IDB_BMP_MOUSE))); void   CMy ...

  9. Lucene.Net 2.3.1开发介绍 —— 三、索引(七)

    原文:Lucene.Net 2.3.1开发介绍 -- 三.索引(七) 5.IndexWriter 索引这部分最后讲的是IndexWriter.如果说前面提到的都是数据的结构,那么IndexWriter ...

  10. MS Project 2007 工期、工时、资源、固定单位、固定工期、固定工时

    0. 基本概念 工期:指完成每项项目任务所经历的实际时间,及开始日期和结束时期之差.Project中,工期的默认单位是天. 工时:指将任务分配给资源后,每个资源执行任务的工作时间.Project中,工 ...