COUNT - Another Very Easy Problem! WOW!!!


This problem is somewhat easier than the problem A Very Easy Problem! because of the super long time limit...


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 almost unlimited computers!!


Each line of the input contains two postisive integer N (1<=N<=5000) and K(1<=K<=N).Input is terminated by a line with N=K=0(this case should not be processed).


For each line, output the number of different partition sheme. To avoid big integers, you may output the answer modudo 1988.


1 1
7 3
0 0


hide comments
babur: 2017-09-01 09:29:23

Classical Dp...learnt so much from this question

kshubham02: 2017-08-24 07:49:59

@nap11, possibilities are - 1,1,5; 1,2,4; 1,3,3; and 2,2,3.

studyfather: 2017-07-22 14:12:16

AC in one go!
a real easy problem!

hamjosh1: 2016-11-16 19:29:34

solved in both top down and bottom up :D

Bhuvnesh Jain: 2016-01-12 22:45:46

1d dp solution with O(n^2)

Last edit: 2016-01-12 22:46:13
Utkarsh Agarwal: 2015-12-09 00:04:04

Too harsh for python codes. C++ gets accepted in .92 sec. python is atleast 10 times slower than c/c++.

xxbloodysantaxx: 2015-07-09 21:58:55

Yet another nice DP problem

nap11: 2015-06-29 10:07:19

plz tell me how it will be 4 for n=7 and k=3?

Last edit: 2015-06-29 15:28:19
Bharath Reddy: 2014-09-14 13:42:55

Looking at the comments helped me arrive at the right algorithm :) Awesome problem though.

Last edit: 2014-09-14 13:43:11
Ouditchya Sinha: 2013-07-19 17:21:41

@Juan Martinez : I'm not sure about JAVA but try declaring the array globally, which worked for me in C++.

Nice problem. :)

Added by:Fudan University Problem Setters
Time limit:10s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64 C99 ERL JS-RHINO OBJC SQLITE
Resource:Time limit: 1000 Years! Memory limit: 2000 GB! Acc%: 100%!