Question link: Click the open link
Question:
Click Open Link
Here the DP practices are:
Write a State X, and then transfer from XGo outX = Y1 + y2 + ···
All Yi values are known.
In this way, we will obtain an equation from unknown to known.
However, DP is from known to unknown. So let's get back ..
# Include <cstdio> # include <iostream> # include <cstring> # include <queue> # include <algorithm> # include <map> # include <cmath> using namespace STD; const int n = 1005; double DP [N] [N]; // DP [I] [J] indicates that I system has been found, and the number of days of J bug int N, s; double solve () {DP [N] [s] = 0.0; For (INT I = N; I> = 0; I --) {for (Int J = s; j> = 0; j --) {if (I = N & J = s) continue; DP [I] [J] = (n-I) * (S-j) * DP [I + 1] [J + 1] + I * (S-j) * DP [I] [J + 1] + (n-I) * j * DP [I + 1] [J] + N * s; DP [I] [J]/= N * s-I * j;} return DP [0] [0];} int main () {While (CIN> N> S) printf ("%. 4f \ n ", solve (); Return 0 ;}
Poj 2096 collecting bugs probability dp (Water