题目链接:http://poj.org/problem?id=2096
#include<cstdio> #include<cstring> #include<iostream> #include<algorithm> using namespace std; const int maxn = 1005; const int INF = 0x3f3f3f3f; double dp[maxn][maxn]; int main() { 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) dp[n][s] = 0,dp[n+1][s] = 0, dp[n][s+1] = 0; else{ 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); } printf("%.4f ",dp[0][0]); }