0

I am trying to figure out a formula to use for figuring out the number of combinations I can create by rearranging two distinct object types, both of which have distinct numbers of themselves.

I essentially want a Combination with Repetition (i.e. (n+r−1)!/r!(n−1)!) but I can only have a certain number of items per object type. What would the modification need to be to account for this?

To give more context, I am trying to find a pattern for the Climbing Stairs problem, in which a person needs to climb x number of stairs by either taking 1 step or 2 steps at a time. The solution involves finding the unique number of ways that a person can make their trek to the top of the stairs.

To break this problem down, I started figuring out the maximum array length and then working down to the minimum array, which would vary depending upon whether the count of stairs x is odd or even. From there, I can see that the number of unique paths for a given number of stairs grows in a Fibonacci sequence, which I could use to solve the problem fairly easily programmatically, but I have a nagging curiosity about what mathematical formula I would need to apply to generate the unique numbers of intermittent arrays.

To illustrate the point further, let's say I have 6 steps. This means that:

  1. I can take 13 unique paths to get to the top of the 6th stair (13 being the 6th number in the Fibonacci sequence)
  2. I can take a maximum of 6 steps of 1 stair at-a-time
  3. I can take a combination of 5 steps with 1 double step and 4 single steps
  4. I can take a combination of 4 steps with 2 double steps and 2 single steps
  5. I can take a minimum of 3 steps of 2 stairs at-a-time

This is the full break down of the unique arrays for 6 steps, traversed by either 1 step or 2:

// Number of steps to traverse = 6
// Total number of unique paths = 13 == (1 + 5 + 6 + 1)

// array length = 6 // number of paths = 1 [1,1,1,1,1,1]

// array length = 5 // number of paths = 5 // items: 1 two, 4 ones [2,1,1,1,1] [1,2,1,1,1] [1,1,2,1,1] [1,1,1,2,1] [1,1,1,1,2]

// array length = 4 // number of paths = 6 // items: 2 twos, 2 ones [2,2,1,1] [2,1,2,1] [2,1,1,2] [1,2,1,2] [1,1,2,2] [1,2,2,1]

// length 3 // number of paths = 1 // items: 3 twos [2,2,2]

Torc
  • 103
  • 1
    Generally speaking, the posted question falls within the realm of enumerating $$x_1 + \cdots + x_k = n ~: ~x_1,\cdots,x_k \in \Bbb{Z},$$ where a lower bound is given to each variable, and zero or more of the variables have an upper bound. See this answer for a blueprint of how to combine Inclusion-Exclusion with Stars-And-Bars to attack this generic type of problem. – user2661923 Nov 01 '24 at 04:45
  • 1
    If each variable must be an element in $~{1,2},~$ then the approach taken in my previous comment might be regarded as overkill. For example, faced with $$x_1 + x_2 + \cdots + x_{10} = 15,$$ (for example), it is simply a matter of choosing which $~5~$ variables will be equal to $~2~$ instead of $~1.~$ So, the enumeration is immediately seen to be $~\displaystyle \binom{10}{5}.$ – user2661923 Nov 01 '24 at 04:51

1 Answers1

2

What you are asking, in essence, is how many ways there are to climb a staircase with $n$ steps, when you can move in steps of one or two, without having a table of Fibonacci numbers, and using combinations, rather than recursion.

The simplest formula is $\binom{n}0+\binom{n-1}1 +\binom{n-2}2 +...$
with the convention that the binomial coefficient is zero if the lower binomial coefficient is more than the upper one.

In your particular case of $n-6$, this would translate to

$\binom60+\binom51+\binom42+\binom33 = 1+5+6+1 =13$

Of course, this is related to the Fibonacci numbers.

With $n$ being the number of $\texttt{steps}$, we could write the desired answer as the summation of the $(n+1)$th Fibonacci number, more succinctly as

$$F(n+1) =\sum_{k=0}^{\lfloor{n/2}\rfloor}\binom{n-k}{k}$$