POJ3014 Cake Pieces and Plates (整数划DP)

本文介绍了一个经典的组合数学问题——如何将m块蛋糕分配到n个盘子中的算法实现。使用动态规划方法解决该问题,并提供了完整的C++代码示例。
                                                                          Cake Pieces and Plates
Time Limit: 5000MS Memory Limit: 131072K
Total Submissions: 5123 Accepted: 1424
Case Time Limit: 1000MS

Description

kcm1700, ntopia, suby, classic, tkwons, and their friends are having a birthday party for kcm1700. Of course, there is a very large birthday cake. They divide the birthday cake into undistinguishable pieces and put them on identical plates. kcm1700 is curious, so he wants to know how many ways there are to put m cake pieces on n plates.

Input

In the only input line, there are two integers n, m (1 ≤ n, m ≤ 4 500), which are the number of the plates and the number of the cake pieces respectively.

Output

If the number of ways is K, just output K mod 1000000007 because K can be very large.

Sample Input

3 7

Sample Output

8

Hint

There are 8 ways to fill 3 plates with 7 cakes, namely (0,0,7), (0,1,6), (0,2,5), (0,3,4), (1,1,5), (1,2,4), (1,3,3), (2,2,3).

题意很简单,就是求将m划分成为n个数的和,问有多少种方法,还是DP吧,呵呵。。。。。。。。

动态方程是:F(i,j)=F(i-j,j)+(i,j-1);

贴上代码:

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值