ACM 递推.doc

  1. 1、有哪些信誉好的足球投注网站(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。。
  2. 2、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载
  3. 3、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
查看更多
ACM 递推.doc

ACM训练赛--递推专题?? 1001: Buy the Ticket Problem 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 wont 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 Source HUANG, Ninghai ?题目分析: ? 题目大意: 电影院买票,收银台没有零钱,而排队买票的人手里拿着的都是100元或是50元,每张票50元,给出拿100或50的各自人数,求出有几种排列方法使得收银台不会因找不出钱而停止! ? 思路: 设m张50元n张100元时的排列方法有f(m,n)种,总人数为m+n;当总人数为m+n-1时,有两种情况: (1)m少1。此时必须要满足mn(若m=n,则m-1 P (2)n少1。排列方法有f(m,n-1)种。当n-1多1时,同理有n*f(m,n-1)种方法。 由以上两种情况得到递推公式: 当m=n时,f(m,n)=n*f(m,n-1); 当mn时,f(m,n)=m*f(m-1,n)+n*f(m,n-1); 当mn时,f(m,n)=0. 下一步就要确定初始条件: 当m=1, n=0时,f(m,n)=1; 当m=1, n=1时,f(m,n)=1. 另外,由于本题的数据比较大,必须要用高精度,而且递归会超时,要用数组来保存数据。那么,选用哪种类型的数组比较好呢?很显然,本题涉及到很大的运算量,用整型的数组比较好。于是,用f[m][n][]代表f(m,n)。 ? 代码: ? #includestdio.h #define c 51????????????????????? //定义数组的长度 #define d 100000000??????? //定义常量,用于整型数组的数据处理 int main() { ??? int m,n,i,j,k,t=1,temp=0,f1,f2; ??? __int64 ff; ??? int f[101][101][c]={0};??????????????????????//数组初始化为0 ??? f[1

文档评论(0)

zhaojq + 关注
实名认证
内容提供者

该用户很懒,什么也没介绍

1亿VIP精品文档

相关文档