Description
James got a bunch of fun coins and decided to use them to play a little game with his friends. On a table with N rows and M columns, every grid in row i and column j has a James coin. The probability of flipping the coin is Pij, and all coin flip events are mutually exclusive. independent.
Now, in M columns of coins, the player chooses 1 coins from each column, a total of M coins, to form a group. In this way, N groups are repeatedly selected, and it is guaranteed that the selected coins cannot be selected again. After the group is selected, the M coins of each group are tossed once. If they all come up heads, the group wins and the total score wins 1 point; otherwise, the group fails and the total score is neither added nor subtracted. Excuse me, if you choose the grouping of coins, what is the maximum mathematical expectation of the total score of the game?
Input
Enter multiple sets of data. The first row of each set of data is N and M, 1≤N≤100, 1≤M≤10, separated by spaces. Next there are N lines, each with M decimals, representing the corresponding P ij in the table .
The input ends with N=M=0, and no result is output for this set of data.
Output
For each set of data, output the maximum mathematical expectation corresponding to the game's total score, rounded to the nearest 4 decimal places. The output of each set of data occupies one line.
Sample Input
2 3 1.0 1.0 1.0 0.5 0.4 0.3 0 0
Sample Output
1.0600
Hint
#include<stdio.h> #include<string> #include<string.h> #include<algorithm> #include<iostream> using namespace std; int m, n; double map[15][110]; intmain() { while (~scanf("%d%d", &n, &m)) { if (!m && !n) break; for (int i = 0; i < n; i++) { for (int j = 0; j < m; j++) { scanf("%lf", &map[j][i]);//注意这里 i j 的位置 } } for (int i = 0; i < m; i++) sort(map[i], map[i] + n); double sum = 0; for (int i = 0; i < n; i++) { double cnt = 1; for (int j = 0; j < m; j++) cnt *= map[j][i]; sum += cnt; } printf("%.4lf\n", sum); } return 0; } /********************************************************************** Problem: 1009 User: leo6033 Language: C++ Result: AC Time:4 ms Memory:2036 kb **********************************************************************/