Choose and divide

Source: Internet
Author: User
The binomial coefficient C (m, n)Is defined
         m!C(m,n) = --------         n!(m-n)!
Given four natural numbers P, Q, R, And S, Compute the result of dividing C (p, q)By C (R, S). The inputinput consists of a sequence of lines. Each line contains four non-negative integer numbers giving values P, Q, R, And S, Respectively, separated by a single space. All the numbers will be smaller than 10,000 P> = QAnd R> = s. The outputfor each line of input, print a single line containing a real number with 5 digits of precision in the fraction, giving the number as described above. you may assume the result is not greater than 100,000,000. sample Input
10 5 14 993 45 84 59145 95 143 92995 487 996 4882000 1000 1999 9999998 4999 9996 4998
Output for sample input
0.12587505606.460551.282230.489962.000003.99960
 
Question: The question is a combinationC (p, q)/C (R, S); then one can be multiplied by one and divided by one.
         m!C(m,n) = -------
         n!(m-n)!
Simplified to m-1) * (m-2)... (m-n + 1)/n !; The number of this numerator is the same as that of the denominator;
Then there will be a subscript;
 
# include <iostream># include <cstdio>using namespace std;int main(){    //freopen("a.txt","r",stdin);    int p,q,r,s;    while(scanf("%d%d%d%d",&p,&q,&r,&s)!=EOF)    {        int i,n;        double ans=1.0;        //if (p - q < q)     q = p - q;        //if (r - s < s)     s = r - s;        for(i=1;i<=q||i<=s;i++)        {            if(i<=q)    ans=ans*(p-q+i)/i;            if(i<=s)    ans=ans/(r-s+i)*i;        }        printf("%.5lf\n",ans);    }    return 0;}

Choose and divide

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.