Collecting Bugs POJ2096
简单的期望DP, 只不过是二维形式, 设\(dp_{i,j}\)为两种分别选了\(i, j\)种后还需要的期望数, 则\(dp_{i,j} = \frac{i*j}{n*s}*dp_{i,j} + \frac{(n-i)*j}{n*s}*dp_{i+1,j} + \frac{i*(s-j)}{n*s}*dp_{i,j+1} + \frac{(n-i)*(s-j)}{n*s}*dp_{i+1,j+1} + 1\), 移项整理即可
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cstdio>
using namespace std;
const int maxn = 1007;
double dp[maxn][maxn];
void run_case() {
int n, s;
cin >> n >> s;
for(int i = n; i >= 0; --i)
for(int j = s; j >= 0; --j) {
if(i == n && j == s) continue;
dp[i][j] = (n*s +(n-i)*j*dp[i+1][j]+(s-j)*i*dp[i][j+1]+(n-i)*(s-j)*dp[i+1][j+1])/(n*s-i*j);
}
cout << dp[0][0];
}
int main() {
//ios::sync_with_stdio(false), cout.tie(0);
cout.flags(ios::fixed);cout.precision(4);
run_case();
//cout.flush();
return 0;
}