I tried this problem for a long time but could not solve.. How to solve it?? Any explanation or hints from expert will be helpful for me..The problem statement is given below:
Given n objects you’d have to tell how many different groups can be chosen if r objects are taken at a time.
Input
Input consists of 100 test cases. Each test case begins with two integers n (0 < n ≤ 50), m (0 ≤ m ≤ n). The next line will contain the labels (numbers in the range 1 to n) of the n objects you are to choose from. Two objects with the same label are considered equivalent. Then in the last line for that test case, you’d have m values for r. There will be a single space separating two consecutive numbers in a line. Input is terminated by a test case where n = 0, you must not process this test case.
Output
For each test case, print the test case number. And for each query number r, print the number of different groups that can be formed if r objects are taken from the given n objects. You can assume that for all input cases, the output will always fit in a 64-bit unsigned integer and (0 ≤ r ≤ n).
Sample Input
5 2
1 2 3 4 5
2 1
4 1
1 2 3 4
2
0 0
Sample Output
Case 1:
10
5
Case 2:
6
Auto comment: topic has been updated by adamantium (previous revision, new revision, compare).
you can solve this problem usin dynamic programing .first, for each type count the number of its occurrences and construct new array "a" contains these counts and let its length = m . i.e [1,2,1,5,5] will be [2,1,2] now let F(i,k,rem) = how many ways we can choose rem objects from the remaining m-i cells if the i_th cell has count = k F(i,k,rem)=F(i+1,a[i+1],rem)+F(i,k-1,rem-1) F(i,k,0)=1; the answer for the problem =F(0,a[0],r)
Couldn't understand.. why this recursive relation will work??
Problem Solved !! Thanks a lot :)