题意:
面前有n个门,选择每个门的概率相同,每个门都对应一个时间,如果时间为正值,就表示此门可以走出去,
时间为负值,表示走此门还是会回到原地,而且还花费时间,但是回到原地以前的记忆就在没了,
也就是说前边的时间作废。求出去的时间期望
思路:
因为会回到原地,所以回到原地后走的期望和没走之前的期望都是一样的,我们定义为E
E = (走出去的时间之和 + 没有走出去时间之和 + 没有走出去的情况次数 * E)/ 总情况次数
E = (走出去的时间之和 + 没有走出去时间之和) / 走出去的情况的次数
# https://blog.csdn.net/qq_38891827/article/details/89521313
#include<bits/stdc++.h>
using namespace std;
const int N = 1e4;
double f[N + 10];
int main(){
int T; cin >> T;
for(int C = 1; C <= T; C ++){
int n; double P; scanf("%lf %d", &P, &n);
P = 1 - P;
for(int i = 1; i <= N; i ++) f[i] = 0;
f[0] = 1;
for(int i = 1; i <= n; i ++){
double p; int m; scanf("%d %lf", &m, &p);
for(int j = N; j >= m; j --){
f[j] = max(f[j], f[j - m] * (1 - p) );
}
}
int res = 0;
for(int i = 1; i <= N; i ++){
if(f[i] >= P) res = i;
}
printf("Case %d: %d\n", C, res);
}
}
一年有n天,m个人,没有两个人生日相同的概率,可以随着m增大递推
p = n(n-1)(n-2)...(n-m+1) / n ^ x
带环的期望dp
列出等式,利用高斯消元求解