题目链接:点击打开链接
#include<stdio.h> #include<iostream> #include<string.h> #include<set> #include<vector> #include<map> #include<math.h> #include<queue> #include<string> #include<stdlib.h> #include<algorithm> using namespace std; #define N 18 double b[1<<N], a[N][N]; int n; int main(){ int i, j, k; while(~scanf("%d",&n)){ for(i=0;i<n;i++) for(j=0;j<n;j++)scanf("%lf",&a[i][j]); int all = 1<<n; b[all-1] = 1; for(k = all-1; k>=0 ; k--) { int siz = 0; for(i=0;i<n;i++)siz += (k>>i&1); for(i=0;i<n;i++) if(k>>i&1) { for(j = 0; j < n; j++) if(i!=j&&(k>>j&1)) b[k^(1<<j)] += b[k]*a[i][j]/((siz-1)*siz/2); } } for(i=0;i<n;i++) printf("%.6lf%c",b[1<<i],i==n-1?'\n':' '); } return 0; }
Codeforces 16E Fish,布布扣,bubuko.com
原文地址:http://blog.csdn.net/qq574857122/article/details/35557553