hdu1133 Buy the Ticket (Carrante number of applications +java large number)

Source: Internet
Author: User

Topic Link: http://acm.hdu.edu.cn/showproblem.php?

pid=1133

Test instructions

Movie tickets, 50 bucks a piece.

There are just 50 pieces in the hand of the M-Man, and there is just 100 in the hand, and the ticket office starts to have no money. Ask, how many ways of queuing, to let everyone buy tickets.

(assuming that the ticket office does not have 50 pieces of change, the person holding 100 will not be able to buy the ticket)

Analysis

Obviously. When M<n, there are 0 ways of arranging.

When the m>=n:

With 0. There are only 50 people in the hand, 1 of them, representing only 100 in the hand.

0110100 such circumstances cannot satisfy the condition (the third person cannot buy it)

We flip the person that contains the third person and his previous (1->0, 0->1)

1000100 appeared this sequence;

0110100 has 4 0, 3 1 1000100 5 0, 2 1

Each of the conditions that cannot be satisfied corresponds to such a sequence so that the condition that cannot be met is jointly owned

C (M+1,m+n);

We calculate the formula is: the legal arrangement method = All arrangement way-illegal arrangement way

So there's F (N) = (-) *m!  *n! ;


And then simplify it again;

F (N) = (m+n)!

* (m-n+1)/(m+1).

Because the data is too large, so the large number of Java to solve

Code

Import Java.util.*;import Java.math.biginteger;public class main{public    static void Main (string[] args) {            int a , b;            Scanner in=new Scanner (system.in);            int cnt=0;            while (In.hasnext ()) {                cnt++;                A=in.nextint ();                B=in.nextint ();                BigInteger Ans=biginteger.one;                if (a==0&&b==0) break;                if (a<b) Ans=biginteger.zero;                else {for                    (int i=1;i<=a+b;i++) {                        ans=ans.multiply (biginteger.valueof (i));                    }                    int mpl= (a-b+1);                    int dvd= (a+1);                    Ans=ans.multiply (biginteger.valueof (MPL));                    Ans=ans.divide (biginteger.valueof (DVD));                }                System.out.println ("Test #" +cnt+ ":");                System.out.println (ANS);}}        



hdu1133 Buy the Ticket (Carrante number of applications +java large number)

Related Article

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.