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
#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;
}