标签:
http://acm.split.hdu.edu.cn/showproblem.php?pid=4336
Special Judge
1 #include <cstdio> 2 #include <cstring> 3 #include <algorithm> 4 #include <cmath> 5 using namespace std; 6 7 double p[22]; 8 double dp[22]; 9 10 int main() 11 { 12 int n; 13 while(~scanf("%d", &n)) { 14 for(int i = 0; i < n; i++) 15 scanf("%lf", &p[i]); 16 double ans = 0; 17 double sum; 18 int cnt; 19 for(int i = 1; i < (1 << n); i++) { 20 sum = 0; cnt = 0; 21 for(int j = 0; j < n; j++) { 22 if(i & (1 << j)) { 23 cnt++; 24 sum += p[j]; 25 } 26 } 27 if(cnt & 1) ans += 1.0 / sum; 28 else ans -= 1.0 / sum; 29 } 30 printf("%f\n", ans); 31 } 32 return 0; 33 }
标签:
原文地址:http://www.cnblogs.com/fightfordream/p/5794791.html