Http://poj.org/problem? Id = 2151
There are t teams and M questions, which give the probability that each team will make each question. Calculate the probability that each team has at least one question and the champion team has at least N questions.
As long as the array is set, it is very intuitive.
DP [I] [J] [k] indicates the probability that the team I solves K questions in the previous J questions, s [I] [J] indicates the probability that a team I can solve a maximum of J questions.
Initialize DP [I] [0] [0] and DP [I] [J] [0], so DP [I] [J] [k] = DP [I] [J-1] [k-1] * A [I] [J] + dp [I] [J-1] [K] * (1-A [I] [J]).
S [I] [J] = DP [I] [m] [0] + dp [I] [m] [1] + ..... + dp [I] [m] [J].
First, find the probability that each team should solve at least one question (p1 = (1-s [1] [0]) * (1-s [2] [0]) * ...... * (1-s [T] [0]).
Then, find that each team is removed by 1 ~ N-1 probability P2 = (s [1] [n-1]-s [1] [0]) * (s [2] [n-1]-s [2] [0]) * ...... * (s [T] [n-1]-s [T] [0]).
Then the answer is p1-p2.
#include <stdio.h>#include <iostream>#include <map>#include <set>#include <list>#include <stack>#include <vector>#include <math.h>#include <string.h>#include <queue>#include <string>#include <stdlib.h>#include <algorithm>#define LL long long#define _LL __int64#define eps 1e-12#define PI acos(-1.0)using namespace std;int m,t,n;double dp[1010][35][35],s[1010][35];double a[1010][35];int main(){while(~scanf("%d %d %d",&m,&t,&n)){if(m == 0 && t == 0 && n == 0) break;for(int i = 1; i <= t; i++){for(int j = 1; j <= m; j++)scanf("%lf",&a[i][j]);}memset(dp,0,sizeof(dp));for(int i = 1; i <= t; i++){dp[i][0][0] = 1;for(int j = 1; j <= m; j++){dp[i][j][0] = dp[i][j-1][0]*(1-a[i][j]);for(int k = 1; k <= j; k++)dp[i][j][k] = dp[i][j-1][k-1]*a[i][j] + dp[i][j-1][k]*(1-a[i][j]);}}memset(s,0,sizeof(s));for(int i = 1; i <= t; i++){for(int j = 0; j <= m; j++){for(int k = 0; k <= j; k++)s[i][j] += dp[i][m][k];}}double p1 = 1;for(int i = 1; i <= t; i++)p1 = p1*(1-s[i][0]);double p2 = 1;for(int i = 1; i <= t; i++)p2 = p2*(s[i][n-1]-s[i][0]);printf("%.3f\n",p1-p2);}return 0;}