题意很短略去不说。
思路:设dp[S] 为已集齐状态S中的各卡片后集齐所有卡片的期望值。
那么方程为dp[S] = 1 + sigma(dp[S + {v}] *p[v]) + (1 - sigma(p[v]))*dp[S] (v是S中不包含的状态)
代码:
#include<cstdio>
#include<iostream>
using namespace std;
const int MAX = 2000000;
const int maxn = 55;
double dp[MAX];
int n;
double p[maxn];
void solve(){
int Ed = 1 << n;
dp[Ed-1] = 0;
double t1,t2;
for(int S = Ed - 2; S >= 0 ; S--){
t1 = 1 ; t2 = 0;
for(int i = 0 ; i < n ; i++){
if(!(S >> i & 1)){
t2 += p[i]*dp[S | 1 << i];
t1 -= p[i];
}
//cout<<t1<<" "<<t2<<endl;
}
dp[S] = (1 + t2) / (1 - t1);
//cout<<S<<" "<<dp[S]<<endl;
}
printf("%.6f\n",dp[0]);
}
int main(){
while(~scanf("%d",&n)){
for(int i=0;i<n;i++)
scanf("%lf",&p[i]);
solve();
}
return 0;
}