数学游戏之乐------给出方案数,求总额&&面额?

来源:互联网 发布:淘宝耐克双肩包 编辑:程序博客网 时间:2024/05/11 04:46

游戏大意:给出付款方案数n?问多少钱和多少种面额及这些面额分别是多少,然后付款方案有n种?

比如:n = 4。其一解为:付10钱,3种面额(1,2, 5)。这四种方法是(10 dup(1)), ( 5 dup(2)) , (2 dup(5)). dup是重复的意思,汇编中的记法。

情况有很多种,给出一种即可。一看就是构造方法。

一种简单解法是,不妨假设面额只有两种(1, 2)。三生万物,1 2通过和运算能产生所有的正整数。假设我们要付款val钱。考虑付多少个买额为2的钱,不够款补1。0个,1个,,,val / 2个 面额为2的钱。共(val / 2 + 1) 种方案付了 val钱。现在题意是给出了方案数 n = (val / 2 + 1)。求val。显然val = (n - 1) * 2。所以该游戏的一个构造方法就是 付 val 钱。用2种面额(1, 2)。


国庆中秋没能回家,实验室大佬发月饼啦 


People don't use cash as often as they used to. Having a credit card solves some of the hassles of cash, such as having to receive change when you can't form the exact amount of money needed to purchase an item. Typically cashiers will give you as few coins as possible in change, but they don't have to. For example, if your change is 30 cents, a cashier could give you a 5 cent piece and a 25 cent piece, or they could give you three 10 cent pieces, or ten 1 cent pieces, two 5 cent pieces, and one 10 cent piece. Altogether there are 18 different ways to make 30 cents using only 1 cent pieces, 5 cent pieces, 10 cent pieces, and 25 cent pieces. Two ways are considered different if they contain a different number of at least one type of coin. Given the denominations of the coins and an amount of change to be made, how many different ways are there to make change?


原创粉丝点击