joj 1026解题报告

 

 1026: The Staircases


ResultTIME LimitMEMORY LimitRun TimesAC TimesJUDGE
3s8192K1590530Standard

One curious child has a set of N little bricks. From these bricks he builds different staircases. Staircase consists of steps of different sizes in a strictly descending order. It is not allowed for staircase to have steps equal sizes. Every staircase consists of at least two steps and each step contains at least one brick. Picture gives examples of staircase for N=11 and N=5:

Your task is to write a program that reads from input numbers N and writes to output numbers Q - amount of different staircases that can be built from exactly N bricks.


Input

Numbers N, one on each line. You can assume N is between 3 and 500, both inclusive. A number 0 indicates the end of input.

 

 


Output

Numbers Q, one on each line.

 


Sample Input

3
5
0

Sample Output

1
2
这道题可以用动态规划和组合数学的思想,这里只说组合数学的思想,主要就是母函数的思想,输入N,那么此时有N个砖块来组成楼梯,我个人理解其实就是把楼梯可以分解成n个有不同砖块数目组成的长方形和正方形,如图中N=5时,有两种分解方法,第一种是分解为一个砖头组成的正方形,和四个方块组成的长方形,第二种是将其分解为一个砖头组成的正方形和四个砖块组成的长方形。并且每输入一个N,那么一定可以按照这种方法分解,那么这个道题就可以变成一道组合计数的问题,从而可以想到用母函数的思想来解决,(1+x^1)(1+x^2).....(1+x^N),算出x^N项的系数,然后再减1,即为所求的解,例如,当N=5的时候,(1+x^1)(1+x^2)(1+x^3)(1+x^4)(1+x^5),求出x^5的系数为3,x^5=1(x^0)*x^5=x^1*x4=x^2*x^3,而第一种1*x^5是不符合情况的,因为,这种相当于只有一个由5个砖块组成的长方形,想象一下,这就是1个楼梯,不符合题意,所以要将这个情况减去。
代码:
语言:c++
 

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值