FZOJ Problem 2103 Bin & Jing in wonderland
Problem 2103 Bin & Jing in wonderland
Accept: 221 Submit: 1175
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
decimal points, which indicates the probability of the final list.
Sample Input
2 3 3
0.3 0.7
1 1 1
2 3 3
0.3 0.7
1 1 2
2 3 3
0.3 0.7
1 2 2
2 3 3
0.3 0.7
2 2 2
Sample Output
0.189000
0.441000
0.343000
#define _CRT_SECURE_NO_DEPRECATE
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
using namespace std;
typedef long long ll;
const int N_MAX = ;
int N, k, r;
double P[N_MAX];
int res[N_MAX];
int num[N_MAX];
ll C[][];
void C_table(){
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-];
}
}
} double all_position() {
double ans = ;
int number = k;
for (int i = ; i <= N;i++) {//把所有已经知道的数放进k个位置中相应的位置所有的放法
if (num[i]) {
ans *= C[number][num[i]];
number -= num[i];
}
}
return ans;
} int main() {
int T;
scanf("%d",&T);
C_table();//组合排列查询表
while (T--) {
memset(num,,sizeof(num));
scanf("%d%d%d",&N,&k,&r);
for (int i = ; i <= N;i++)
scanf("%lf",&P[i]);
double u = ,p=,ans=;
for (int i = ; i <= r; i++) {
scanf("%d", &res[i]);
num[res[i]]++;//记录该礼物的数量
u *= P[res[i]];//把已知的那些礼物的概率累乘得到的是一种情况下这些礼物的放置位置,再乘上所有可能的放置位置就得到这部分礼物概率
}
sort(res+,res+r+);
for (int i = ; i < res[];i++) {//把编号比res[1]还小的礼物的概率全部累加
p += P[i];
} for (int i = r; i <=k;i++) {
if (i > r) {
u *= P[res[]];
num[res[]]++;
}
ans += u*pow(p, k - i)*all_position(); }
printf("%.6lf\n",ans);
}
return ;
}
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个编号最大的 ...
- Bin & Jing in wonderland(概率,组合数学)
Problem 2103 Bin & Jing in wonderland Accept: 201 Submit: 1048 Time Limit: 1000 mSec Memor ...
- FZOJ Problem 2219 StarCraft
...
- FZOJ Problem 2150 Fire Game
...
- FZOJ Problem 2148 Moon Game
Proble ...
- FZOJ Problem 2107 Hua Rong Dao
...
- FZOJ Problem 2110 Star
...
- UVa 102 - Ecological Bin Packing(规律,统计)
题目来源:https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&category=3&pa ...
- UVa - 102 - Ecological Bin Packing
Background Bin packing, or the placement of objects of certain weights into different bins subject t ...
随机推荐
- linux - mysql 安装教程
环境介绍>>>>>>>>>>>>>>>>>> 操作系统:Centos 7 mysql数据库版 ...
- 用户价值模型 CITE :https://www.jianshu.com/p/34199b13ffbc
RFM用户价值模型的原理和应用 ▌定义 在众多的用户价值分析模型中,RFM模型是被广泛被应用的:RFM模型是衡量客户价值和客户创利能力的重要工具和手段,在RFM模式中,R(Recency)表示客户购 ...
- java String中的replace(oldChar,newChar) replace(CharSequence target,CharSequence replacement) replaceAll replaceFirst 面试题:输入英文语句,单词首字符大写后输出 char String int 相互转换
package com.swift; import java.util.Scanner; public class FirstChat_ToCaps_Test { public static void ...
- const 修饰成员函数 前后用法(effective c++ 03)
目录 const在函数后面 const修饰成员函数的两个作用 const在函数前面 总结 const在函数后面 类的成员函数后面加 const,表明这个函数不会对这个类对象的数据成员(准确地说是非静态 ...
- 转 Hystrix入门指南 Introduction
https://www.cnblogs.com/gaoyanqing/p/7470085.html
- Java 多线程同步生产者消费者问题-monitor
对这个问题更深一点理解是,每一个线程都在竞争这个类的实例的monitor对象. java会为每个object对象分配一个monitor,当某个对象的同步方法(synchronized methods ...
- Spring Cloud构建微服务架构(二)分布式配置中心
注:此文不适合0基础学习者直接阅读,请先完整的将作者关于微服务的博文全部阅读一遍,如果还有疑问,可以再来阅读此文,地址:http://blog.csdn.net/sosfnima/article/d ...
- python numpy复制array
numpy快速复制array 前段时间想到一个算法,需要实现array的自我复制,直接上代码,两种复制方式, 整体复制 a=[[10,10,50,50],[10,10,40,50]] np.tile( ...
- LeetCode(282) Peeking Iterator
题目 Given an Iterator class interface with methods: next() and hasNext(), design and implement a Peek ...
- poj 1017 装箱子问题 贪心算法
题意:有1*1到6*6的的东西,需要用6*6的箱子将它们装起来.问:至少需要多少个6*6箱子 思路: 一个瓶子怎么装东西最多?先装石头,在装沙子,然后装水. 同样放在本题就是先装6*6然后5*5... ...