简单的概率DP,可以看出n,m必须是同奇偶的,因为每多拿一次,剩余的个数只能+1或者-1,这样看来,n,m就必须是同奇偶的。
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
double dp[2][110];
int main() {
int c, n, m, i, j;
while (~scanf("%d", &c), c) {
scanf("%d%d", &n, &m);
if (m > c || m > n || (m+n)%2) {
puts("0.00");
continue;
}
if (n > 1000) n = 1000+n%2;
memset(dp, 0, sizeof(dp));
dp[0][0] = 1;
int nw, pr;
nw = 0, pr = 1;
for (i = 1;i <= n;i++) {
for (j = 0;j <= i && j <= c;j++) {
dp[pr][j] = (j?dp[nw][j-1]*(c-j+1)/c:0)+dp[nw][j+1]*(j+1)/c;
}
nw ^= 1, pr ^= 1;
}
printf("%.3lf\n", dp[nw][m]);
}
}