1
$\begingroup$

Given a row of length $N$, and a set of 1D bars having lengths $A[1...M]$, how many ways I can fill the row?
A is an integer array,
the bars are having dimensions $\{ 1\times A_1, 1\times A_2, 1\times A_3,..., 1\times A_M \}$
The row can also be considered as $1\times N$ grid.
2 Bars with equal length has to be considered as $2$ distinct bar not $1$.
Bars are same from either direction, so just by reversing bars there wont be any new arrangement

I thought solving the problem by converting it into :
Let, Each space is an element of $1\times 1$, and all spaces are indistinguishable and similar.
No of space $K=N-sum(A_1,A_2,...,A_M)$
Now the answer will be
No of arrangements of $M$ distinct elements and $K$ similar elements.

But again with no hope as could not find any solution for both the problems.

**Examples : **
$N=3, A=\{1,1\} $
$ M=2, K=1$
$Ans = 6 $

$N=3, A=\{1,2\} $
$ M=2, K=0$
$Ans = 2 $

$N=4, A=\{1,2\} $
$ M=2, K=1$
$Ans = 6 $

$N=3, A=\{2\} $
$ M=1, K=1$
$Ans = 2 $

$N=10, A=\{7\} $
$ M=1, K=3$
$Ans = 4 $

  • 0
    Thanks Reverse wont make new arrangements I've edited the question as u requested2017-01-15

2 Answers 2

1

Any arrangement of bars can be obtained by the following procedure:

I. Write a bitstring of length $K+M$ consisting of $K$ zeros and $M$ ones. II. Replace each zero with a space. III. Replace each one with a bar.

Step I can be performed in $\binom{K+M}M$ ways.

Step II can be performed in only one way, since the spaces are indistinguishable.

Step III. can be performed in $M!$ ways, since the bars are distinguishable.

The answer is $\boxed{\binom{K+M}MM!}=\boxed{\frac{(K+M)!}{K!}}.$

  • 0
    Thanks
    Can u solve this one also http://cs.stackexchange.com/questions/68766/no-of-ways-to-fill-a-row-1xn-grid-with-a-set-of-1d-bars-with-some-constraints
    2017-01-15
0

I found one easy approach :
Convert the problem further to No of distinct permutation of M distinct letters(the bars) and K letters(the spaces) of same type
Here Total letters $n=M+K,$
Total letters of 1 category $n_i$ $ = K $
Hence total distinct permutation = $\frac{(\sum_i n_i)!}{\prod_i n_i!}$ = $\frac{(M+K)!}{K}$

I found the formula here .