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 ...
随机推荐
- Python -- 可迭代对象和迭代器
5.9 可迭代对象 可迭代对象: str , list , tuple , set , dict , range 1.在Python中,但凡内部有__iter__方法的对象,都是可迭代对象 2.查看对 ...
- js实现23种设计模式(收藏)
js实现23种设计模式 最近在学习面向对象的23种设计模式,使用java 和 javascript 实现了一遍,但是因为目前大三,还没有比较正规的大项目经验,所以学习的过程种我觉得如果没有一定的项目经 ...
- SAP HANA
DROP PROCEDURE ""."ZCONCAT_EKKO_EBN"; CREATE PROCEDURE ""."ZCONCA ...
- pandas中的随机排序和抽样
1.随机重排序 使用take()随机排序 如: df.take([54]) #采取索引为54的数据 可以借助np.random.permutation()函数随机排序 permutation()函 ...
- k8s的Pod控制器
pod的配置清单常见选项: apiVersion,kind,metadata,spec,status(只读) spec: containers: nodeSelector: nodeName: res ...
- paper:synthesizable finite state machine design techniques using the new systemverilog 3.0 enhancements 之 standard verilog FSM conding styles(二段式)
1.Two always block style with combinational outputs(Good Style) 对应的代码如下: 2段式总结: (1)the combinational ...
- Linux系统入门-Bash初识
目录 Linux系统入门-Bash初识 Bash Shell介绍 Bash Shell的作用 Bash的两种使用方式 命令提示符 shell的基础语法 shell的基本特性 命令补全 linux快捷键 ...
- Artwork Gym - 101550A 离线并查集
题目:题目链接 思路:每个空白区域当作一个并查集,因为正着使用并查集分割的话dfs会爆栈,判断过于复杂也会导致超时,我们采用离线反向操作,先全部涂好,然后把黑格子逐步涂白,我们把每个空白区域当作一个并 ...
- HDU - 1251 统计难题(Trie树)
有很多单词(只有小写字母组成,不会有重复的单词出现) 要统计出以某个字符串为前缀的单词数量(单词本身也是自己的前缀). 每个单词长度不会超过10. Trie树的模板题.这个题内存把控不好容易MLE. ...
- UVa 12167 & HDU 2767 强连通分量 Proving Equivalences
题意:给出一个有向图,问最少添加几条有向边使得原图强连通. 解法:求出SCC后缩点,统计一下出度为0的点和入度为0的点,二者取最大值就是答案. 还有个特殊情况就是本身就是强连通的话,答案就是0. #i ...