https://ac.nowcoder.com/acm/contest/874/A
题意:2个号,上到N级的次数期望,给出每级可能的上升概率,失败换号。
dp[i][j]表示 当前账号分别是i,j级,并且下一场比赛使用i级的账户参赛,达到n级仍需要的参赛次数的期望.
#include <bits/stdc++.h>
using namespace std;
int t;
int n;
double a[305];
double dp[305][305];
int main(){
scanf("%d", &t);
while(t--) {
scanf("%d", &n);
for (int i = 0; i < (n); ++i)
scanf("%lf", &a[i]);
for (int i = 0; i < (n+1); ++i)
dp[i][n] = 0,dp[n][i] = 0;
for (int k = (2 * n - 2); k >= (0); --k)
{
int l = k - n + 1;
if(l < 0) l = 0;
for (int i = (l); i <= (n - 1); ++i)
{
int j = k - i;
if(j < 0)
break;
dp[i][j] = (a[i] * dp[i + 1][j] + (1 - a[i]) * (a[j] * dp[j + 1][i] + 1) + 1) / (a[i] + a[j] - a[i] * a[j]);
}
}
printf("%.4lf\n", dp[0][0]);
}
return 0;
}