POJ2096——概率DP——Collecting Bugs
http://poj.org/problem?id=2096
dp[i][j] 表示 已经侵入了i个子系统,已经拥有了j种类的期望
状态转移方程 dp[i][j] = dp[i][j]*(i*j)/(n*s) + dp[i+1][j]*(n-i)*j/(n*s) + dp[i][j+1]*i*(s-j)/(n*s) + dp[i+1][j+1]*(n-i)*(s-j)/(n*s) + 1
dp[i][j] 可以从已经侵入了i+1个子系统,拥有j种类的情况中删掉一分子系统得到i+1中有n-i中选择情况
dp[i][j] 也可以从dp[i][j]转移,交换
其余同理
/************************************************ * Author :Powatr * Created Time :2015-8-28 16:00:55 * File Name :C.cpp ************************************************/ #include <cstdio> #include <algorithm> #include <iostream> #include <sstream> #include <cstring> #include <cmath> #include <string> #include <vector> #include <queue> #include <deque> #include <stack> #include <list> #include <map> #include <set> #include <bitset> #include <cstdlib> #include <ctime> using namespace std; #define lson l, mid, rt << 1 #define rson mid + 1, r, rt << 1 | 1 typedef long long ll; const int MAXN = 1e5 + 10; const int INF = 0x3f3f3f3f; const int MOD = 1e9 + 7; double dp[1010][1010]; int main(){ int n, s; while(~scanf("%d%d", &n, &s)){ memset(dp, 0, sizeof(dp)); for(int i = n;i >= 0; i--){ for(int j = s; j >= 0; j--){ if(i == n && j == s) continue; dp[i][j] = dp[i][j+1]*i*(s-j)/n/s + dp[i+1][j]*(n-i)*j/n/s + dp[i+1][j+1]*(n-i)*(s-j)/n/s + 1; dp[i][j] /= (1.0 - ((double)i*j/n/s)); } } printf("%f\n", dp[0][0]); } return 0; }