#include #define maxn 2222 double prob[maxn][maxn]; int i, j; void init() { /* * prob[i][j] represents the probability that alice picks jth element if there are i elements in total. * Take 1, 2, 3, 4 * In the next move we can reach A -> 1, 2, 3 or B -> 2, 3, 4 * hence prob[i][j] = 1 - 0.5 * ( prob[i-1][j] {this denotes A} + prob[i-1][j-1] { we get an offset of 1 look at B} ) * As we have noticed this depends only on N and the position not on the actual value present at that position. Hence we can precompute for all N. */ for(i=1; i < maxn; i++) { for(j = 1; j<= i;j++) { prob[i][j] = 1.0 - 0.5 * (prob[i-1][j] + prob[i-1][j-1]); } } return; } int a[maxn]; int main() { int nt, n; init(); scanf("%d",&nt); while(nt--) { double ans = 0.0; scanf("%d",&n); for(i=1; i<=n; i++) scanf("%d",&a[i]); for(i=1;i<=n;i++) ans += prob[n][i] * a[i]; printf("%.6lf\n",ans); } return 0; }