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

Source: Internet
Author: User
Tags ticket

Title 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 M-man, there is just 100 in the hand, and the ticket office starts to have no money. Ask, how many kinds of queues, can let everyone buy tickets.

(If 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, representing only 50 people in the hand, 1, representing only 100 pieces of the hand.

0110100 This condition does not satisfy the condition (cannot be bought by the third person)

We flip the person that includes 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

Every unsatisfied case corresponds to a condition in which such a sequence cannot be satisfied.

C (M+1,m+n);

We calculate the formula is: the legal arrangement means = 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 use the Java large number 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);}}        



Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.

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.