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官方提供 ...
随机推荐
- ASIHttpRequest:创建队列、下载请求、断点续传、解压缩
ps:本文转载自网络:http://ryan.easymorse.com/?p=12 感谢作者 工程完整代码下载地址:RequestTestDownload1 可完成: 下载指定链接的zip压缩文件 ...
- MySQL server version for the right syntax to use near 'type=InnoDB' at line 1
转载请注明出处:http://blog.csdn.net/bettarwang/article/details/40180271 在执行一个Hibernate的演示样例时,配置了<propert ...
- DIV 与 Table 嵌套
当然可以了.对于DIV定义表示一块可显示 HTML 的区域. Specifies a container that renders HTML. 注释此元素在 Internet Explorer 3.0 ...
- jquery之radio
<td class="queryTitle" width="80px">是否启用</td> <td class="que ...
- C# 模拟键盘按键操作
[DllImport("user32.dll")] public static extern IntPtr keybd_event(byte bVk, byte bScan, in ...
- Html与css基础
1.html的定义 (1).html:超文本标记语言(HyperText Markup Language),它主要包括"头"(Head)和"主体"(Body)两 ...
- return 与 finally
(function hello() { try { return console.log('return'); } catch (e) { } finally { console.log('final ...
- Tornado 模板支持“控制语句”和“表达语句”的表现形式
Tornado 的模板支持“控制语句”和“表达语句”,控制语句是使用 {% 和 %} 包起来的 例如 {% if len(items) > 2 %}.表达语句是使用 {{ 和 }} 包起来的,例 ...
- QTableWidget简单操作
使用Qt设计师工具,在窗体上添加Table Widget控件,这样就可以使用ui全局变量来调用该控件了. Table Widget控件的应用 (1)设置列数和行数 //设¦¨¨置?列¢D数ºy和¨ª行 ...
- 锋利jQuery 学习整理之 第六章 jQuery 与Ajax 的应用
1.Ajax 的XMLHttpRequest 对象 XMLHttpRequest 是Ajax 的核心,它是Ajax 实现的关键---发送异步请求.接受响应及执行回调都是通过它来完成的.XMLHttpR ...