Description
The "Harry Potter and the Goblet of Fire" will be on show in the next few days. As a crazy fan of Harry Potter, you will go to the cinema and have the first sight, won’t you?
Suppose the cinema only has one ticket-office and the price for per-ticket is 50 dollars. The queue for buying the tickets is consisted of m + n persons (m persons each only has the 50-dollar bill and n persons each only has the 100-dollar bill).
Now the problem for you is to calculate the number of different ways of the queue that 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 will be stopped on the occasion that the ticket-office has no 50-dollar bill but the first person of the queue only has the 100-dollar bill.
Input
The input file contains several test cases. Each test case is made up of two integer numbers: m and n. It is terminated by m = n = 0. Otherwise, m, n <=100.
Output
For each test case, first print the test number (counting from 1) in one line, then output the number of different ways in another line.
Sample Input
3 0
3 1
3 3
0 0
Sample Output
Test #1:
6
Test #2:
18
Test #3:
180
推导过程https://blog.csdn.net/doc_sgl/article/details/8880468
因为最后结果比较大所以用大数乘法,而n+m小于等于200,也就是大数乘小数,所以开两个数组就行
#include <iostream>
#include <string.h>
#include <stdio.h>
using namespace std;
int b[2000],c[2000];
int n,m;
void mult(int A,int B[],int C[]){
int len1=1999;
while(b[len1]==0) len1--;//找到最高位的位置
int c=0;
int i;
for(i=0;i<=len1;i++){
C[i]=B[i]*A+c;
c=C[i]/10;
C[i]=C[i]%10;
}
if(c){//防止漏了最大的一位的判断
while(c){
C[i++]=c%10;
c/=10;
}
}
}
int main(){
int t=1;
while(scanf("%d %d",&n,&m)!=EOF){
if(n==0 && m==0)
break;
if(m>n){
printf("Test #%d:\n",t++);
printf("0\n");
continue;
}
memset(b,0,sizeof(b));
c[0]=1;
b[0]=1;//一定要初始化,不然怎么乘都是0
for(int i=2;i<=m+n;i++){
if(i==n+1){
mult(n+1-m,b,c);
}
else{
mult(i,b,c);
}
memset(b,0,sizeof(b));
for(int i=0;i<2000;i++){//接着乘与i求阶乘
b[i]=c[i];
}
memset(c,0,sizeof(c));
}
int len1=1999;
while(b[len1]==0) len1--;
printf("Test #%d:\n",t++);
for(int i=len1;i>=0;i--)//记得从最高位开始输出
printf("%d",b[i]);
printf("\n");
}
}