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官方提供 ...
随机推荐
- C++ multimap 的插入,遍历,删除
#include <iostream> #include <map> #include <string> using namespace std; int main ...
- 《学习opencv》笔记——矩阵和图像操作——cvCalcCovarMatrix,cvCmp and cvCmpS
矩阵和图像的操作 (1)cvCalcCovarMatrix函数 其结构 void cvCalcCovarMatrix(计算给定点的均值和协方差矩阵 const CvArr** vects,//给定向量 ...
- JMeter 参数化、检查点、集合点
参数化:简单的来理解一下,我们录制了一个脚本,这个脚本中有登录操作,需要输入用户名和密码,假如系统不允许相同的用户名和密码同时登录,或者想更好的模拟多个用户来登录系统. 这个时候就需要对用户名和密 ...
- python应用之文件属性浏览
import time,os def showFilePROPERTIES(path): for root,dirs,files in os.walk(path,True): print('位置:' ...
- oracle之case when
oracle case when 的用法 http://www.cnblogs.com/xiaowu/archive/2011/08/17/2143445.html(转) http://www.cnb ...
- C#图像处理(5):无损保存图片
C#使用默认方法对图像进行保存的时候图像会有损失,以下提供无损保存的方法: /// <summary> /// 无损保存图片 /// </summary> /// <pa ...
- delete语句与reference约束 FK_subplan_job_id冲突问题,导致job无法删除解决办法
在SQL Server 2008上删除已运行维护计划后,维护计划job没有自动删除掉,手工再删除维护计划job,提示删除失败. 错误现象:delete 语句与 reference 约束"F ...
- (转)css中通常会用到浮动与清除,也是一个必须掌握的知识点,概念性的东西不多说,下面举几个例子,来说明它的用法:1.文字环绕效果 2.多个div并排显示 3.清除浮动(默认显示)
一.文字环绕效果: html代码如下: 1 <body> 2 3 <style type="text/css"> 4 #big img {float: le ...
- Android SDCard和内部存储中gcc编译后的可执行文件无法运行提示 cannot execute - Permission denied
原因是mount的方式问题,root后运行 su mount -o rw,remount /mnt/sdcard //SDCard mount -o rw,remount /mnt/interna ...
- Codeforces 229D Towers
http://codeforces.com/problemset/problem/229/D 题意:有n(1<=n<=5,000)座塔排在一条直线上,从左到右每个塔的高度分别为hi(1&l ...