HDU 1133 Buy The Ticket

Source: Internet
Author: User

Problem DescriptionThe "Harry Potter and the Goblet of Fire" would be on show in the next few days. As a crazy fan of Harry Potter, you'll go to the cinema and has the first sight, won ' t you?

Suppose the cinema only have one ticket-office and the price for per-ticket are dollars. The queue for buying the tickets are consisted of M + N persons (m persons each have the 50-dollar bill and N persons E Ach only has the 100-dollar bill).

Now, the problem for are to calculate the number of different ways of the "the" and the buying process won ' t be stopped From the first person till the last person.
Note:initially the Ticket-office has no money.

The buying process is stopped on the occasion that the Ticket-office have no 50-dollar bill but the first person of th E queue only had the 100-dollar bill. Inputthe input file contains several test cases. Each test case was made up of Numbers:m and N. It is terminated by M = n = 0. Otherwise, M, N <=100. Outputfor each test case, first print the test number (counting from 1) and then output the number of different W Ays in another line. Sample INPUT3 0 Sample outputtest #1:6Test #2:18Test #3:180
formula: (C (M+n, N)-C (M+n, m+1)) * m! * n! simplification (m+n)! * (m-n+1)/(m+1) by formula: C (M, n) = m! /(n!* (M-N)! ) Derivation (C (M+n, N)-C (M+n, m+1)) * m! * n!: The total arrangement minus the illegal arrangement, and because each person is different multiplied by its own full rank
#include<stdio.h>#include<string.h># define N1010intA[n], M, N;voidFact () {intI, J, s, r =0; for(i =2; I <= (m+n); i++) { for(j =0; J < N; J + +) {s= A[j] * i +R; R= S/Ten; A[J]= s%Ten; } }} //Find out (m+n)!voidSum () {intI, J, C = m-n+1, d = m+1, B[n], k =0, S, r =0; for(i =0; i < N; i++) A[i]*=C; for(i =0; I < n1; i++) { if(A[i] >9) {A[i+1] + = A[i]/Ten; A[i]%=Ten; } } //Find out (m+n)! * (m-n+1)i = n1; while(A[i] = =0) i--; for(j = i; J >=0; j--) B[k++] =A[j]; for(i =0; I < K; i++) {s= B[i] +Ten*R; R= s%D; B[i]= S/D; } //Find out (m+n)! * (m-n+1)/(m+1)i =0; while(B[i] = =0) i++; for(j = i; J < K; J + +) printf ("%d", B[j]); printf ("\ n");}intMain () {intK =0; while(SCANF ("%d%d", &m, &n), m+N) {k++; printf ("Test #%d:\n", K); if(M <N) printf ("0\n");//If you take 100 more people than 50, then there's no such platoon . Else{memset (A,0,sizeof(a)); a[0] =1; Fact (); Sum (); } } return 0;}

HDU 1133 Buy The Ticket

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.