FZU 2103 Bin & Jing in wonderland

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

For each case, output a float number with 6 digits after the decimal points, which indicates the probability of the final list.

Sample Input

4
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.027000
0.189000
0.441000
0.343000

组合数学问题,把前r大中最小的找出来,小于这个的看做是一个物品,然后枚举最小的这个的个数。
事先把组合数预处理一下。
#include<cstdio>
#include<cstring>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<algorithm>
#include<functional>
using namespace std;
typedef long long LL;
const int maxn = 1e2 + 10;
int T, n, m, k, r[maxn], cnt[maxn];
LL C[maxn][maxn];
double p[maxn];

void init()
{
	for (int i = 1; i < 54; i++)
	{
		C[i][0] = C[i][i] = 1;
		for (int j = 1; j < i; j++)
		{
			C[i][j] = C[i - 1][j] + C[i - 1][j - 1];
		}
	}
}

double now()
{
	double ans = 1;
	int tot = m;
	for (int i = 1; i <= n; i++)
	{
		if (cnt[i])
		{
			ans *= C[tot][cnt[i]];
			tot -= cnt[i];
		}
	}
	return ans;
}

int main()
{
	init();
	scanf("%d", &T);
	while (T--)
	{
		scanf("%d%d%d", &n, &m, &k);
		memset(cnt, 0, sizeof(cnt));
		for (int i = 1; i <= n; i++) scanf("%lf", &p[i]);
		for (int i = 1; i <= k; i++) scanf("%d", &r[i]), cnt[r[i]]++;
		sort(r + 1, r + k + 1, greater<int>());
		double q = 0, ans = 0, u = 1;
		for (int i = 1; i <= k; i++) u *= p[r[i]];
		for (int i = 1; i < r[k]; i++) q += p[i];
		for (int i = k; i <= m; i++)
		{
			if (i > k) cnt[r[k]]++, u *= p[r[k]];
			ans += u * pow(q, m - i) * now();
		}
		printf("%.6lf\n", ans);
	}
	return 0;
}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值