传送门

[http://acm.hdu.edu.cn/showproblem.php?pid=1133]

题目描述和分析



代码

#include<iostream>
#include<string.h>
using namespace std; void Multiply(int a[],int z)//大数a[]和小数z相乘,结果存储在a[]中
{
int maxn = 2000;
int c = 0;
for(int j=maxn-1;j>=0;j--)//用z乘以a[]的每一位
{
int x = a[j] * z + c;
a[j] = x % 10;
c = x / 10;
}
} int main()
{
int m,n,num=0;
while(1)
{
cin >> m >> n;
if(!m && !n)
break; cout << "Test #" << ++num << ":" << endl; if(m<n)//m<n,没有符号条件的排列
{
cout << 0 << endl;
continue;
} const int maxn = 2000;
int a[maxn],i,j;
memset(a,0,sizeof(a));
a[maxn-1] = 1; if(n==0)//此时全是拿50元的人,直接输出m!的结果
for(i=2;i<=m+n;i++)//计算m!
Multiply(a,i); else if(n>=1)//此时按照公式计算,避开除法
{
for(i=2;i<=m+n;i++)
if(i!=m+1)//如果,某一项恰好是分母(m+1),则不乘以这一项
Multiply(a,i); Multiply(a,m-n+1);//根据公式,最后还要乘以(m-n+1)一项
} for(i=0;i<maxn;i++)
if(a[i])//从i开始,非零
break;
for(j=i;j<maxn;j++)//输出
cout << a[j];
cout << endl;
} return 0;
}

Buy the Ticket HDU 1133的更多相关文章

  1. Buy the Ticket HDU 1133 递推+大数

    题目连接: http://acm.hdu.edu.cn/showproblem.php?pid=1133 题目大意: 有m+n个人去买电影票,每张电影票50元,  m个人是只有50元一张的,  n个人 ...

  2. Buy the Ticket HDU 1133 卡特兰数应用+Java大数

    Problem Description The "Harry Potter and the Goblet of Fire" will be on show in the next ...

  3. Buy the Ticket HDU - 1133 大数dp

    题意: 演唱会门票售票处,那里最开始没有零钱.每一张门票是50元,人们只会拿着100元和50元去买票,有n个人是拿着50元买票,m个人拿着100元去买票. n+m个人按照某个顺序按序买票,如果一个人拿 ...

  4. 【HDU 1133】 Buy the Ticket (卡特兰数)

    Buy the Ticket Problem Description The "Harry Potter and the Goblet of Fire" will be on sh ...

  5. hdu 1133 Buy the Ticket(Catalan)

    Buy the Ticket Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) T ...

  6. hdu 1133 Buy the Ticket (大数+递推)

    Buy the Ticket Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  7. HDU——1133 Buy the Ticket

    Buy the Ticket Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others) T ...

  8. HDU 1133 Buy the Ticket (数学、大数阶乘)

    Buy the Ticket Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

  9. HDUOJ---1133(卡特兰数扩展)Buy the Ticket

    Buy the Ticket Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/32768 K (Java/Others)To ...

随机推荐

  1. Postgresql - jsonb_pretty & dateStyle

    1. SHOW datestyle; DateStyle ----------- ISO, MDY(1 row) INSERT INTO container VALUES ('13/01/2010') ...

  2. 18LaTeX学习系列之---LaTeX的参考文献

    目录 目录 前言 (一)简单的参考文献 1.说明 2.源代码 3.输出效果 (二)以文件管理的方式 1.说明: 2.源代码: 3.输出效果 (三)直接从源网站获取 1.说明 2.操作 目录 本系列是有 ...

  3. OSPF单区域配置

    OSPF单区域配置 实验环境:华为模拟器eNSP 现在有这样一个拓扑图: 我想要让R1可以ping通R3,显然目前是不行的: <R1>ping 192.168.2.2 PING 192.1 ...

  4. VMware NAT 设置原理

    1.网络地址转换(NAT):默认使用VMnet8 (强烈推荐) 这种访问模式指的是虚拟机不占用主机所在局域网的ip,通过使用主机的NAT功能访问局域网和互联网,意味着虚拟机可以访问局域网中的其他电脑, ...

  5. [java基础]一文理解java多线程必备的sychronized关键字,从此不再混淆!

    java并发编程中最长用到的关键字就是synchronized了,这里讲解一下这个关键字的用法和容易混淆的地方. synchronized关键字涉及到锁的概念, 在java中,synchronized ...

  6. File类_构造函数

    File类:用来将文件或者文件夹封装成对象方便对文件或或文件夹的属性信息进行操作File对象可以作为参数传递给流的构造函数 import java.io.File; public class File ...

  7. HDU - 5078 水题

    题意:最大困难=距离 / 相邻时间 #include<cstring> #include<cstdio> #include<cmath> #define ll do ...

  8. vscode中iframe的使用

    vscode中iframe由于某种原因不支持本地页面,比如<iframe src ="index.html" width="300" height=&qu ...

  9. UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position 1: ordinal not in range(128)

    对于写python的人来说,这个异常一点不陌生,只要涉及到中文字符串的操作,一不小心就会出错.关于这个问题的解释,找到一篇好文,分享一下. 原文地址:https://blog.csdn.net/u01 ...

  10. python函数查询、数学和比较操作符、二元操作符

    http://www.runoob.com/python/func-number-round.html print().input()用户输入输出,格式为字符串 len() 求字符串的长度 str() ...