Arthur HNOI2015 (probability DP)

Portal

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 f [ i ] [ j ] f[i][j] represents r r rounds, the first i i months before and i i chose j j a probability
that a card out of the final probability is
p i = j = 0 i 1 f [ i 1 ] [ j ] ( 1 ( 1 p ) r j ) p_i=\sum_{j=0}^{i-1}f[i-1][j]*(1-(1-p)^{r-j})
f f transferred to enumerate the current election not vote on it
f [ i ] [ j ] = f [ i 1 ] [ j ] ( 1 p ) r j + f [ i 1 ] [ j 1 ] ( 1 ( 1 p ) r ( j 1 ) ) f[i][j]=f[i-1][j]*(1-p)^{r-j}+f[i-1][j-1]*(1-(1-p)^{r-(j-1)})

#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;
}
Published 610 original articles · won praise 94 · views 50000 +

Guess you like

Origin blog.csdn.net/sslz_fsy/article/details/103602215