Suppose there are two bags with 10 balls and 20 balls respectively.If it is always necessary to select at least one ball from each bag. Then, total number of ways to select 3 balls out of these will be :
C(1,10)* C(2,20) + C(2,10)*C(1,20)
Similarly if we need to take total of k balls: where k <= min(10,20) ie min(balls in bag 1, balls in bag 2).
This will be:
C(1,10)*C(k-1,20) + C(2,10)*C(k-2,20)+......+C(k-1,10)*C(1,20)
Can this be generalised to a easy and less time consuming relation for a given k,n1 and n2 where n1 and n2 are balls in bag 1 and bag 2 respectively.
Note: Only two bags are present in all cases.
To remove this from unanswered queue:
As per vandermonde's identity we have
$$\color{red}{\binom{n_1}{0}\binom{n_2}{k}}+\binom{n_1}{1}\binom{n_2}{k-1}+\binom{n_1}{2}\binom{n_2}{k-2}+\dots+\binom{n_1}{k-1}\binom{n_2}{1}+\color{red}{\binom{n_1}{k}\binom{n_2}{0}}\\=\binom{n_1+n_2}{k}$$
so by subtracting, we get:
$$\binom{n_1}{1}\binom{n_2}{k-1}+\binom{n_1}{2}\binom{n_2}{k-2}+\dots+\binom{n_1}{k-1}\binom{n_2}{1}\\=\binom{n_1+n_2}{k}-\binom{n_2}{k}-\binom{n_1}{k}$$
Alternatively phrased, combine the bags and count how many ways you can select $k$ balls from the combined bag. Remove from your count the number of ways the balls all came from the same original bag.
Note also: the above identity does not require that $0\leq k\leq \min(n_1,n_2)$