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官方提供 ...
随机推荐
- 奔五的人学IOS:swift练手与csdn,最近学习总结
早在五月份就准备開始学习ios开发,当时还是oc,学习了几天,最终不得其法.到了ios8开放,再加swift的出现.从10月份開始.最终找到了一些技巧,学习起来还算略有心得. 今天把我在学习swift ...
- 实施双工通信框架:SignalR
SignalR:基于Asp.net平台构建,利用JavaScript或者Websockets,实现在客户端与服务端异步通信的框架. Html5新规范:WebSocket
- linq读书笔记1-linq 初步
至于linq是什么之类的已经有过太多的文章介绍,亦不清楚的胡朋友可以自己搜索一下便可以得到大量的答案 为了体验linq究竟能带给我们什么体验,我们直接从代码入手: string[] words = n ...
- ASP.net(C#)利用SQL Server实现注册和登陆功能
说说我现在吧,楼主现在从事的事IT行业,主攻DotNet技术:当然这次上博客园我也是有备而来,所有再次奉献鄙人拙作,以飨诸位,望诸位不吝赐教. 世界上大多数的工作都是熟练性的工种,编程也不例外,做久了 ...
- (五)CodeMirror - 关于htmlmixed中包含script脚本
最近发现个问题,场景如下: 当创建的mode类型为htmlmixed,且内容中包含javascript脚本,且是闭包立即执行: 如果内容是使用JQuery函数.html()插入到DOM中后再创建cod ...
- Qt添加窗口背景图片、Label图片显示、、Label文字显示
一.添加窗口背景图片 重写MainWindow绘制事件 void MainWindow::paintEvent(QPaintEvent *event) { QPainter painter(this) ...
- Mac系统cocos2dx + android 开发环境配置
Mac系统cocos2dx + android 开发环境配置 /****************************************************** 这遍文章主要转载自:htt ...
- rman全库恢复到不同主机,不同实例名,不同目录下
一.配置目标主机的ip.hostname及与源端主机的连通性 1.配置目标主机IP 使用图形界面配置IP: administration----network---修改IP(指定静态IP) deact ...
- EL表达式取整
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%> 1. <fm ...
- php 远程下载图片到本地
大家好,从今天开始,小弟开始写写博客,把自己在工作中碰到的问题的解决方法纪录下来,方便以后查找,也给予别人方便,小弟不才,第一次写博客,有什么不足之处请指出,谢谢! 今天纪录的是怎么通过PHP远程把图 ...