Bin & Jing in wonderland(概率,组合数学)
Accept: 201 Submit: 1048 Time Limit: 1000 mSec Memory Limit : 32768 KB
Problem Description
Bin has a dream that he and Jing are both in a wonderland full of beautiful gifts. Bin wants to choose some gifts for Jing to get in her good graces.
There are N different gifts in the wonderland, with ID from 1 to N, and all kinds of these gifts have infinite duplicates. Each time, Bin shouts loudly, “I love Jing”, and then the wonderland random drop a gift in front of Bin. The dropping probability for gift i (1≤i≤N) is P(i). Of cause, P(1)+P(2)+…+P(N)=1. Bin finds that the gifts with the higher ID are better. Bin shouts k times and selects r best gifts finally.
That is, firstly Bin gets k gifts, then sorts all these gifts according to their ID, and picks up the largest r gifts at last. Now, if given the final list of the r largest gifts, can you help Bin find out the probability of the list?
Input
The first line of the input contains an integer T (T≤2,000), indicating number of test cases.
For each test cast, the first line contains 3 integers N, k and r (1≤N≤20, 1≤k≤52, 1≤r≤min(k,25)) as the description above. In the second line, there are N positive float numbers indicates the probability of each gift. There are at most 3 digits after the decimal point. The third line has r integers ranging from 1 to N indicates the finally list of the r best gifts’ ID.
Output
Sample Input
Sample Output
Source
“高教社杯”第三届福建省大学生程序设计竞赛
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
using namespace std;
double p[], dp[];
typedef long long LL;
LL C[][];
int num[];
int a[];
void db(){
C[][] = C[][] = ;
for(int i = ; i < ; i++){
C[i][] = C[i][i] = ;
for(int j = ; j < i; j++){
C[i][j] = C[i - ][j] + C[i - ][j - ];
}
}
}
int main(){
int T, N, k, r;
scanf("%d", &T);
db();
while(T--){
scanf("%d%d%d", &N, &k, &r);
dp[] = ;
for(int i = ; i <= N; i++){
scanf("%lf", p + i);
dp[i] = dp[i - ] + p[i];
}
double ans = ;
memset(num, , sizeof(num));
int mi = 0x3f3f3f3f;
for(int i = ; i <= r; i++){
scanf("%d", a + i);
num[a[i]]++;
mi = min(mi, a[i]);
}
int now = k;
for(int i = mi + ; i <= N; i++){
if(!num[i])continue;
ans *= C[now][num[i]] * pow(p[i], num[i]);
now -= num[i];
}
double ans1 = ;
for(int i = num[mi]; i <= k - r + num[mi]; i++){
ans1 += C[k - r + num[mi]][i] * pow(p[mi], i) * pow(dp[mi - ], k - r + num[mi] - i);
}
printf("%.6lf\n", ans * ans1);
}
return ;
}
Bin & Jing in wonderland(概率,组合数学)的更多相关文章
- FZOJ Problem 2103 Bin & Jing in wonderland
...
- FZU - 2103 Bin & Jing in wonderland
FZU - 2103 Bin & Jing in wonderland 题目大意:有n个礼物,每次得到第i个礼物的概率是p[i],一个人一共得到了k个礼物,然后按编号排序后挑选出r个编号最大的 ...
- 20140323组队赛 2012福建省第三届ACM省赛题目
A - Solve equation Time Limit:1000MS Memory Limit:32768KB 64bit IO Format:%I64d & %I64u ...
- django使用笔记
django的具体使用可以看官方手册http://djangobook.py3k.cn,这里主要记录使用django中遇到的问题. 1.中文编码问题. 因为我们用到的东西基本上都有中文,在settin ...
- django开发总结:
一,关于setting目录中的“DEBUG” DEBUG=False 把DEBUG从True改成False后就会出现(必需指定404和500错语页面,如上图的目录结构)找不到页面的错误.原因是DEBU ...
- CTR校准
普遍预测CTR不准,需要校准.例如.boosted trees and SVM预測结果趋于保守.即预測的概率偏向于中值:而对于NaiveBayes预測的概率,小概率趋于更小.大概率趋于更大.经常使用的 ...
- 阿里面试题:为什么Map桶中个数超过8才转为红黑树
(为什么一个是8一个是6:防止频繁来回转换小消耗性能) 这是笔者面试阿里时,被问及的一个问题,应该不少人看到这个问题都会一面懵逼.因为,大部分的文章都是分析链表是怎么转换成红黑树的,但是并没有说明为什 ...
- django项目的配置文件settings.py详解
我们创建好了一个Python项目(mysite/)之后,需要在项目中添加模块应用(polls/),在模块应用中添加处理功能逻辑,如添加模块中的视图处理函数(polls.views.index()),这 ...
- 【5】Django项目配置settings.py详解
夫唯不争,故天下莫能与之争 --老子<道德经> 本节内容 1.项目配置文件settings.py介绍 2.数据库配置[MySQL] 3.创建模型对象并和数据库同步 4.python官方提供 ...
随机推荐
- js为鼠标添加右击事件
<script language="javascript"> /*document.oncontextmenu=Youji;*/ //为当前文档添加鼠标右击事件,防 ...
- Building bridges_hdu_4584(排序).java
Building bridges Time Limit: 3000/1000 MS (Java/Others) Memory Limit: 65535/32768 K (Java/Others) ...
- core_cm3文件函数一览
core_cm3是ARM公司推出来的统一规定,这是对下游芯片厂商的统一规定,因此可以再Cortex-M3(CM3)之间进行移植.此文件中定义了一些对特殊功能寄存器的C语言形式的操作,本质上是内敛汇编和 ...
- Ubuntu 10.04下安装Qt
sudo apt-get install qt4-dev-tools qt4-doc qt4-qtconfig qt4-demos qt4-designer qt-creator 其中: qt4-de ...
- JavaScript学习笔记之 数组方法一 堆栈 和队列
数组的方法 以及 堆栈的操作的方法 JavaScript是一种弱类型语言,不像其它程序语言需要严格定义数据类型.在JavaScript中数组可以任意修改变动,这样也就出现了一个问题,如果边遍历数组边操 ...
- oracle 自动添加序号列 排序
select HSL.sortno, HSL.B, HSL.A, row_n ...
- dug
http://blog.csdn.net/ysy441088327/article/details/8992393 http://www.cnblogs.com/Leo_wl/p/4423922.ht ...
- arm汇编(c内嵌汇编及c和汇编互调)
C语言编译成汇编: arm-linux-gcc -S test.c -o test.S C语言编译成可执行文件: arm-linux-gcc test.c -o test 多个文件编译链接: arm- ...
- CI框架uri去掉index.php
CI框架的入口是index.php,所以url实际上要多出一个index.php,非常不美观.我使用的是apache服务器,要开启mod_rewrite服务才可以. sudo a2enmod rewr ...
- JavaScript中的一些细节
1.设置id / class等属性 用 setAttribute 设置一些常规属性如 id ,className 的时候经常不起作用,只能用 object.id = value 这样来设置 news_ ...