思路:d[i]表示从i个人已变成吸血鬼到所以都变成吸血鬼天数的期望,那么则有d[i]=(d[i+1]+1)p1*p+(d[i]+1)*(1-p1)*p. p1=(i(n-i))/C(n,2)
#include<iostream>
#include<cstdio>
using namespace std;
const int maxn=100008;
int main()
{
int T,n;
double p;
double dp[maxn];
cin>>T;
while(T--)
{
cin>>n>>p;
dp[n]=0;
for(int i=n-1;i>0;i--)
{
double y=(double)n*(n-1)/2;
double x=(double)i*(n-i);
double p1=(x/y)*p;
dp[i]=dp[i+1]+1/p1;
}
printf("%.3f\n",dp[1]);
}
return 0;
}