Test Instructions: ACM Competition, a total of M, T team, Pij said that team I solved the probability of the J question, ask each team to solve at least one problem and the champions team at least solve the probability of the n problem.
Analysis: Probability dp,dp[i][j][k] represents the first team, the first J, the probability of solving K, Sum[i][j] represents the first team, the probability of making a 1-j question, ans1 equals,
T team, at least the probability of solving a problem, Ans2 said T team, at least to solve a problem, but not more than N-1 the probability of a problem, finally with ANS1-ANS2 can.
The code is as follows:
#pragma COMMENT (linker, "/stack:1024000000,1024000000") #include <cstdio> #include <string> #include < cstdlib> #include <cmath> #include <iostream> #include <cstring> #include <set> #include < queue> #include <algorithm> #include <vector> #include <map> #include <cctype> #include < cmath> #include <stack> #define Lson l,m,rt<<1#define Rson m+1,r,rt<<1|1//#include <tr1/ unordered_map> #define FREOPENR freopen ("In.txt", "R", stdin) #define FREOPENW freopen ("OUT.txt", "w", stdout) using Namespace std;//using namespace std:: tr1;typedef Long Long ll;typedef pair<int, int> p;const int INF = 0x3f3f3f3f; Const double inf = 0x3f3f3f3f3f3f;const LL LNF = 0x3f3f3f3f3f3f;const Double PI = ACOs ( -1.0); const double EPS = 1e-8;const int MAXN = 5e4 + 5;const LL mod = 10000000000007;const int N = 1e6 + 5;const int dr[] = {-1, 0, 1, 0, 1, 1,-1, -1};const int dc[] = {0, 1, 0,-1, 1,-1, 1, -1};const char *hex[] = {"0000 "," 0001 "," 0010 "," 0011 "," 0100 "," 0101 "," 0110 "," 0111 "," 1000 "," 1001 "," 1010 "," 1011 "," 1100 "," 1101 "," 1110 "," 1111 "};inline ll GCD (ll A, ll b) {return b = = 0? A:GCD (b, a%b); }int N, m;const int mon[] = {0, 31, 29, 31, 30, 31, 0, +, +,, +, +, +, +, +, 31};const int monn[] N, H, H, C, h, 31};inline int Min (int a, int b) {return a < b? A:b;} inline int Max (int a, int b) {return a > b a:b;} inline ll Min (ll A, ll b) {return a < b a:b;} inline ll Max (ll A, ll b) {return a > b a:b;} inline bool Is_in (int r, int c) {return R >= 0 && r < n && C >= 0 && C < m;} Double dp[2][35][35];d ouble a[1005][35];d ouble sum[1005][35];int main () {int t; while (scanf ("%d%d", &n, &m, &t) = = 3 && m+n+t) {for (int i = 1; I <= m; ++i) F or (int j = 1; j <= N; ++j) scanf ("%lf", &a[i][j]); memset (DP, 0, sizeof DP); dp[1][0][0] = dp[0][0][0] = 1.0; int cnt = 0; for (int i = 1; I <= m; ++i, cnt ^= 1) {for (int j = 1; j <= N; ++j) for (int k = 0; K <= J ++K) Dp[cnt][j][k] = dp[cnt][j-1][k] * (1.0-a[i][j]) + dp[cnt][j-1][k-1] * A[i][j]; Sum[i][0] = 0.0; for (int k = 1; k <= N; ++k) sum[i][k] = Sum[i][k-1] + dp[cnt][n][k]; } Double ans1 = 1.0, Ans2 = 1.0; for (int i = 1; I <= m; ++i) ans1 *= sum[i][n]; for (int i = 1; I <= m; ++i) ans2 *= sum[i][t-1]; printf ("%.3f\n", ans1-ans2); } return 0;}
POJ 2151 Check The difficulty of problems (probability DP)