1 #include<cstdio> 2 3 int main() 4 { 5 int n; 6 double a[21]; 7 while (~scanf("%d",&n)) 8 { 9 for (int i=0;i<n;++i) 10 scanf("%lf",&a[i]); 11 double temp,ans=0; 12 for (int i=1;i< (1<<n);++i) 13 { 14 temp=0; 15 int ct=0; 16 for (int j=0;j<n;++j) 17 if (i & (1<<(j) ) ) 18 { 19 ct++; 20 temp+=a[j]; 21 } 22 if (ct & 1) ans+=1/temp; 23 else ans-=1/temp; 24 } 25 printf("%.4f\n",ans); 26 } 27 return 0; 28 }
hdu4336 Card Collector,布布扣,bubuko.com
原文:http://www.cnblogs.com/code-painter/p/3751054.html