hdu 1133 Buy the Ticket (大数+递推)
Buy the Ticket
Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)
Total Submission(s): 4185 Accepted Submission(s): 1759
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.
简单题。推出递推公式就差不多了。
//0 MS 324 KB Visual C++
/* 递推公式:
ans[n][m]=(n+m)!*(n-m+1)/(n+1);
*/
#include<stdio.h>
#include<string.h>
#define N 10000
int f[][]={};
void mul(int a[],int n)
{
int temp=;
for(int i=;i<;i++){
temp+=n*a[i];
a[i]=temp%N;
temp/=N;
}
}
void div(int a[],int n)
{
int temp=;
for(int i=;i>=;i--){
temp=temp*N+a[i];
a[i]=temp/n;
temp%=n;
}
}
void init()
{
f[][]=;
for(int i=;i<=;i++){
memcpy(f[i],f[i-],*sizeof(int));
mul(f[i],i);
}
}
int main(void)
{
int n,m,k=;
init();
while(scanf("%d%d",&n,&m),n+m)
{
printf("Test #%d:\n",k++);
if(m>n){
puts("");continue;
}
int ans[];
memcpy(ans,f[n+m],*sizeof(int));
mul(ans,n-m+);
div(ans,n+); int i=;
for(;!ans[i];i--);
printf("%d",ans[i]);
while(i--) printf("%04d",ans[i]);
printf("\n");
}
return ;
}
hdu 1133 Buy the Ticket (大数+递推)的更多相关文章
- HDU 1133 Buy the Ticket (数学、大数阶乘)
Buy the Ticket Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)To ...
- hdu 1133 Buy the Ticket(Catalan)
Buy the Ticket Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- HDU——1133 Buy the Ticket
Buy the Ticket Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) T ...
- HDOJ/HDU 1133 Buy the Ticket(数论~卡特兰数~大数~)
Problem Description The "Harry Potter and the Goblet of Fire" will be on show in the next ...
- hdu 1133 Buy the Ticket
首先,记50的为0,100的为1. 当m=4,n=3时,其中的非法序列有0110010; 从不合法的1后面开始,0->1,1->0,得到序列式0111101 也就是说,非法序列变为了n-1 ...
- HDU 1133 Buy the Ticket 卡特兰数
设50元的人为+1 100元的人为-1 满足前随意k个人的和大于等于0 卡特兰数 C(n+m, m)-C(n+m, m+1)*n!*m! import java.math.*; import java ...
- HDU 1297 Children’s Queue (递推、大数相加)
Children’s Queue Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others) ...
- HDU-1041-Computer Transformation,大数递推,水过~~
Computer Transformatio ...
- hdu 5335 Walk Out(bfs+斜行递推) 2015 Multi-University Training Contest 4
题意—— 一个n*m的地图,从左上角走到右下角. 这个地图是一个01串,要求我们行走的路径形成的01串最小. 注意,串中最左端的0全部可以忽略,除非是一个0串,此时输出0. 例: 3 3 001 11 ...
随机推荐
- 【Linux】wget: command not found的两种解决方法
1.rpm 安装 下载wget的RPM包: http://mirrors.163.com/centos/6.8/os/x86_64/Packages/wget-1.12-8.el6.x86_64.rp ...
- web3.js_1.x.x--API(二)/合约部署与事件调用
web3.js_1.x.x的使用和网上查到的官方文档有些不同,我对经常使用到的API进行一些整理,希望能帮到大家 转载博客:http://www.cnblogs.com/baizx/p/7474774 ...
- com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column
com.mysql.jdbc.exceptions.jdbc4.MySQLSyntaxErrorException: Unknown column …… 出现这个异常的很大可能性是 数据库是没有问题的 ...
- Java 使用Apache POI读取和写入Excel表格
1,引入所用的包 <dependency> <groupId>org.apache.poi</groupId> <artifactId>poi-ooxm ...
- laravel构造函数跳转失败
<?php namespace App\Http\Controllers\Admin; use Illuminate\Http\Request; use App\Http\Requests;us ...
- SVN 命令整理
1.将文件checkout到本地目录 svn checkout path(path是服务器上的目录) 例如:svn checkout svn://192.168.1.35/pro/domain 如果开 ...
- jenkins+maven+docker集成java发布(一)自动发布
JAVA项目持续集成发布 标签(空格分隔): java jenkins 微服务中持续集成自动发布是很重要的一个环节,将不同的模块应用自动部署到一台或者N台服务器中如果采用人工部署的方式不太现实 git ...
- go学习笔记-变量和常量
变量和常量 变量 基本写法 //定义一个名称为"variableName",类型为"type"的变量 var variableName type //定义三个类 ...
- 使用 -命令行-给-python-安装whl文件,
whl文件下载到哪个位置,命令行就切入到哪里: 我的在D盘目录下,所以命令行切进D盘(CD):方式如下: 列出<用户目录>下的目录(dir): 因为我安装了2个版本的python所以给py ...
- 从浏览器或者Webview 中唤醒APP
本文来自网易云社区 作者:刘新奇 移动互联时代,很多互联网服务都会同时具备网站以及移动客户端,很多人认为APP的能帮助建立更稳固的用户关系,于是经常会接到各种从浏览器.webview中唤醒APP的需求 ...