题目大意:
就是现在有一场比赛有M道题(<= 30), 一共有T个队伍参赛( <= 1000), 现在知道每只队伍做出每道题的概率,问比赛结束之后所有队伍都有过题且过题最多的队伍过了N题或以上的概率( N <= M)
大致思路:
就是一个典型的dp吧 ( ﹁ ﹁ ), 过程见代码注释
Result : Accepted Memory : 15996 KB Time : 125 ms
/*
* Author: Gatevin
* Created Time: 2014/12/3 14:44:18
* File Name: Asuna.cpp
*/
#include<iostream>
#include<sstream>
#include<fstream>
#include<vector>
#include<list>
#include<deque>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cctype>
#include<cmath>
#include<ctime>
#include<iomanip>
using namespace std;
const double eps(1e-8);
typedef long long lint;
/*
* 用dp[i][j][k]表示第i个队伍在前j道题中做出k道德概率,那么
* dp[i][j][k] = dp[i][j - 1][k - 1]*p[i][j] + dp[i][j - 1][k]*(1 - p[i][j]) 0 < k < j
* dp[i][j][k] = dp[i][j - 1][k - 1]*p[i][j] k == j
* dp[i][j][k] = dp[i][j - 1][k]*(1 - p[i][j]) k == 0
* 那么这样可以知道每个队伍做出的题目在0~m之间的概率
* 用sp[i]表示第i个队伍做出1 ~ n - 1道题的概率 sp[i] = ∑dp[i][m][1 ~ n - 1]
* 用s[i][j]表示前i个队伍中有j个做出了n题或以上的概率
* 则s[i][j] = s[i - 1][j]*sp[i] + s[i - 1][j - 1]*(1 - sp[i] - dp[i][m][0]) 0 < j < i
* s[i][j] = s[i - 1][j]*sp[i] j == 0
* s[i][j] = s[i - 1][j - 1]*(1 - sp[i] - dp[i][m][0]) j == i
* 最后的结果就是∑s[t][1~t]
*/
//这题没有卡精度,看见POJ2151的discuss里面好多人因为.lf 和.f 的问题发了好多帖子,表示想起某只队友...
int m, t, n;
double dp[1010][31][31];
double p[1010][31];
double s[1010][1010];
double sp[1010];
int main()
{
while(scanf("%d %d %d", &m, &t, &n), n || t || m)//刚开始n和m打反了交了一发WA...囧
{
for(int i = 1; i <= t; i++)
for(int j = 1; j <= m; j++)
scanf("%lf", &p[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++)
for(int k = 0; k <= j; k++)
{
if(k == 0) dp[i][j][k] = dp[i][j - 1][k]*(1 - p[i][j]);
else if(k == j) dp[i][j][k] = dp[i][j - 1][k - 1]*p[i][j];
else dp[i][j][k] = dp[i][j - 1][k - 1]*p[i][j] + dp[i][j - 1][k]*(1 - p[i][j]);
//cout<<dp[i][j][k]<<" dp["<<i<<"]["<<j<<"]["<<k<<"] "<<endl;
}
}
memset(sp, 0, sizeof(sp));
for(int i = 1; i <= t; i++)
for(int k = 1; k < n; k++)
sp[i] += dp[i][m][k];
memset(s, 0, sizeof(s));
s[0][0] = 1;
for(int i = 1; i <= t; i++)
for(int j = 0; j <= i; j++)
{
if(j == 0) s[i][j] = s[i - 1][j]*sp[i];
else if(j == i) s[i][j] = s[i - 1][j - 1]*(1 - sp[i] - dp[i][m][0]);
else s[i][j] = s[i - 1][j]*sp[i] + s[i - 1][j - 1]*(1 - sp[i] - dp[i][m][0]);
}
double ans = 0;
for(int i = 1; i <= t; i++)
ans += s[t][i];
printf("%.3f\n", ans);
}
return 0;
}