UVA_10375
将组合数化简一下边乘边除即可。
#include<stdio.h>
#include<string.h>
int P, Q, R, S;
void solve()
{
int i, j, k;
double ans = 1.0;
if(P - Q < Q)
Q = P - Q;
if(R - S < S)
S = R - S;
for(i = 1; i <= S || i <= Q; i ++)
{
if(i <= Q)
ans = ans * (P - Q + i) / i;
if(i <= S)
ans = ans / (R - S + i) * i;
}
printf("%.5lf\n", ans);
}
int main()
{
while(scanf("%d%d%d%d", &P, &Q, &R, &S) == 4)
solve();
return 0;
}