Consideration of each card to obtain a probability out of it so you can easily calculate the expected
number of times a card to be considered related to the account of its rounds, while taking into account a number of rounds in the previous point a few cards related to the election
so make
represents
rounds, the first
months before and
chose
a probability
that a card out of the final probability is
transferred to enumerate the current election not vote on it
#include<bits/stdc++.h>
#define cs const
using namespace std;
cs int N = 225;
int T, n, r;
double p[N]; int d[N];
double pw[N][N], f[N][N];
int main(){
scanf("%d", &T);
while(T--){
scanf("%d%d", &n, &r);
for(int i = 1; i <= n; i++){
scanf("%lf%d", &p[i], &d[i]);
pw[i][0] = 1;
for(int j = 1; j <= r; j++) pw[i][j] = pw[i][j - 1] * (1 - p[i]);
}
f[0][0] = 1;
for(int i = 1; i <= n; i++){
for(int j = 0; j <= r; j++){
f[i][j] = f[i - 1][j] * pw[i][r - j] + f[i - 1][j - 1] * (1 - pw[i][r - j + 1]);
}
} double ans = 0;
for(int i = 1; i <= n; i++){
double p = 0;
for(int j = 0; j < r; j++) p += f[i - 1][j] * (1 - pw[i][r - j]);
ans += p * d[i];
} printf("%.10lf\n", ans);
} return 0;
}