r-combination from n objects where objects can be indistinguishable or distinguishable

61 Views Asked by At

How to solve this kind of combinatorial problem. You are given n objects and you have to find out r-combination from it.

As example there are 4 objects.. 1 2 2 3..you have to find out how many 3-combination exists.. The answer is 3.. (1 2 3) (1 2 2) (2 2 3)

So if there are n objects how to solve this problem..

1

There are 1 best solutions below

0
On BEST ANSWER

You tagged DP and combinatorics, so i will try to merge both:

First of all, you need to know that doesn't matter what are the objects, the only thing that matters is that you have $1$ one, $2$ two and $1$ three.
So call $a_i:=\text{number of times we have $i$-th object}$($a_1=1,a_2=2,a_3=3$ in your example) and suppose you have $n$ objects, so we have the family of numbers $\{a_i\}_{i\in [n]}$. So, in your recursion you want to take track of how many numbers you have left of each kind and you want to know how many have you chosen, so your recursion will look like:$$f(A,r,i) = \left\{ \begin{array}{ll} [i=1 \wedge (a_1\leq r \vee r=0) ] & i=1 \\ f(A,r,i-1)+f(A\setminus \{a_i\}\cup \{a_i-1\} ,r-1,i)[a_i\neq 0] & \mbox{if } i>1 \end{array} \right.$$ where [P] is $1$ if the sentence inside is true or $0$ if not and $A$ is an array(the set operations represent replace in that array).
From that recurrence, you will see that the DP must catch how many objects you have left to put and how many elements of each kind you have.

On the other hand, by combinatorics you must see that you are dealing here with the problem of counting how many arrays $(x_1,\ldots, x_n)$ have the property$$\left\{ \begin{array}{ll} x_i\leq a_i \\ \sum _{i=1}^n x_i=r \end{array}\right.$$ If you do not care about the $a_i's$ you will have the well known stars and bars theorem there, i.e., ${r+n-1}\choose{n-1}$. The only problem is that you put restrictions on the summands and you have to include and exclude solutions, so in your example call $$f(y_1,y_2,y_3):=\{ \text{ solutions to $\sum x_i=r$ if we take $x_1>y1$,$x_2>y_2$ and $y_3>x_3$}\}.$$ So you want to take every solution of the sum minus the ones that doesn't care of your restriction, so in your example:
$$f(-1,-1,-1)\setminus (f(1,-1,-1)\cup f(-1,2,-1) \cup f(-1,-1,1)) = |f(-1,-1,-1)|+\sum _{i=1}^3 (-1)^{i}\sum _{b_1<\cdots <b_i}|\bigcap _{l=1}^i f(-1,\cdots ,a_{b_l},\cdots ,-1)|.$$ So you just need to use stars and bars in each instance of that inclusion exclusion.

P.S: you will have to deal with $2^n$ sums there, but you can treat it too as a recursion.