A probability DP problem.
Title Link: Http://codeforces.com/contest/540/problem/D
The main topic: An island has r stone, s scissors, p cloth, they randomly pick out two encounters, if not the same species, there will be a disappearance, respectively, the last island to find only one species of probability.
We use Dp[i][j][k] to store I stone, j scissors, k cloth, the survival probability of a species, total dp three times, calculated the probability of three species respectively.
First, we need to initialize the probability of the species to be asked, and here in the case of rocks, it is not difficult to understand dp[i][0][0]=1.0 for I from 1 to R.
Then, transfer the equation in the following states:
Wherein, DP[I][J][K] can be obtained by dp[i][j-1][k],dp[i][j][k-1],dp[i-1][j][k], for example, to Dp[i][j-1][k]--i stone, j-1 scissors and K-cloth when the probability of survival, multiplied by the corresponding proportion I *j; the other three practices are the same.
The results can be obtained by a single memory search. In the same vein, ask for three times respectively.
AC Code:
#include <bits/stdc++.h>using namespace Std;typedef long LL; #define MAXN 110double Dp[maxn][maxn][maxn];bool Vis[maxn][maxn][maxn];int R, S, p;void init () {memset (Vis, false, sizeof (VIS)); memset (DP, 0, sizeof (DP)); Vis[0][0][0] = true;} void Dfs (int i, int j, int k) {if (I < 0 | | J < 0 | | K < 0) return; if (Vis[i][j][k]) return; Vis[i][j][k] = true; int sum = 0; DFS (I, j-1, k); sum + = i * j; Dp[i][j][k] + = (double) (i * j) * Dp[i][j-1][k]; DFS (I, J, k-1); sum + = J * k; Dp[i][j][k] + = (double) (J * k) * dp[i][j][k-1]; DFS (I-1, J, K); Sum + = k * I; Dp[i][j][k] + = (double) (k * i) * dp[i-1][j][k]; if (sum = = 0) return; Dp[i][j][k]/= (double) sum;} int main () {scanf ("%d%d%d", &r, &s, &p); Init (); for (int i = 1; I <= R; i++) dp[i][0][0] = 1.0; DFS (R, S, p); printf ("%.10LF", Dp[r][s][p]); Init (); for (int i = 1; I <= s; i++) dp[0][i][0] = 1.0; DFS (R, S, p); printf ("%.10lf", Dp[r][s][p]); Init (); for (int i = 1; I <= p; i++) dp[0][0][i] = 1.0; DFS (R, S, p); printf ("%.10lf\n", Dp[r][s][p]); return 0;}
Codeforces div.301d Bad Luck (probabilistic dp+ memory Search)