# n fish, numbered from 1 to n , live in a lake. Every day right one pair of fish meet, and the probability of each other pair meeting is the same. If two fish with indexes i and j meet, the first will eat up the second with the probability a ij , and the second will eat up the first with the probability a ji  = 1 - a ij . The described process goes on until there are at least two fish in the lake. For each fish find out the probability that it will survive to be the last in the lake.-笔试面试资料

n fish, numbered from 1 to n , live in a lake. Every day right one pair of fish meet, and the probability of each other pair meeting is the same. If two fish with indexes i and j meet, the first will eat up the second with the probability a ij , and the second will eat up the first with the probability a ji  = 1 - a ij . The described process goes on until there are at least two fish in the lake. For each fish find out the probability that it will survive to be the last in the lake. pipipapi
`#include<bits/stdc++.h>  using namespace std;  const int N = 1<<19; const int M = 19;  int n; double f[N],g[M][M];  int count(int x){ 	int cnt = 0; 	while(x){ 		cnt += (x&1); 		x >>= 1; 	} 	return cnt; }  void solve(){ 	f[(1 << n) - 1] = 1; 	int tot = (1 << n) - 1; 	for(int i = tot-1; i ; i--){ 		int num = count(i) ; 		for(int j = 0; j < n; j++) 			if(!(i>>j&1)) 				for(int k = 0;k < n; k ++){ 					if(j == k) continue; 					if(i>>k&1) 						f[i] +=  1.0*f[i|(1<<j)]*g[k][j]/(num*(num+1)/2); 				} 	} }  void answer(){ 	for(int i = 0; i < n ; i ++ ) 		cout << fixed << setprecision(6) << f[(1<<i)] << " "; }  int main(){ 	cin >> n; 	for(int i = 0; i < n; i++) 		for(int j = 0; j < n ;j++) 			cin >> g[i][j]; 	solve(); 	answer(); 	return 0; }`

www.qklbishe.com 