POJ:1283 Moving Computer(限制划分个数的整数划分)

Description

Assurance Company of Moving (ACM) is a company of moving things for people. Recently, some schools want to move their computers to another place. So they ask ACM to help them. One school reserves K trucks for moving, and it has N computers to move. In order not to waste the trucks, the school ask ACM to use all the trucks. That is to say, there must be some computers in each truck, and there are no empty trucks. ACM wants to know how many partition shemes exists with moving N computers by K trucks, the ACM ask you to compute the number of different shemes with given N and K. 
You needn't care with the order. For example N=7,K=3, the the following 3 partition instances are regarded as the same one and should be counted as one sheme. 
1 1 5 
1 5 1 
5 1 1 
Each truck can carry 200 computers at most. 

Input

Each line of the input contains two postisive integer N (1<=N<=200) and K(1<=K<=N).Input is terminated by a line with N=K=0.

Output

For each line, output the number of different partition sheme . The result may be larger than 2^32, so you should care with the precision.

Sample Input

1 1
7 3
0 0

Sample Output

1
4

Hint

The four partition shemes of the second sample are: 
1 1 5 
1 2 4 
1 3 3 
2 2 3 


我看到网上很多人都是用递推递推转移方程度dp[n][k]=dp[n-1][k-1]+dp[n-k][k],dp[n][k]代表 表示k辆卡车装n台电脑的方法数
这条递推式是怎么来的我没还想懂,

我是通过把这道题转换成: 每辆卡车都至少有一台电脑,所以每辆卡车都先分配一台电脑,
然后剩下的n-k台电脑再分配到k辆卡车里(此时,就可以允许有的卡车不放电脑),这样题目就转化成跟之前做过的POJ1664一样的题目。
即没限制划分个数的整数划分。

#include <stdio.h>
int main()
{
	int n, m;
	while (scanf("%d%d", &m, &n),m+n)
	{
		__int64 dp[205] = { 1 };
		m -= n;
		for (int i = 1; i <= n; i++)
		{
			for (int j = i; j <= m; j++)
			{
				dp[j] += dp[j - i];
			}
		}
		printf("%I64d\n", dp[m]);
	}
	return 0;
}



  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值