Long Legged Larry

Long Legged Larry can climb 2, 3, or n n stairs at a time, where n n is the number of stairs he has climbed already ( n > 0 n>0 ). For example, if he is on stair 7, he can climb up to the stairs 9, 10, or 14, but nothing in between. So, how many different ways can he climb exactly 20 stairs?

Clarification : For n = 2 n=2 , climbing up 2 stairs and climbing up n n stairs is the same. i.e. There is only 1 way to climb up 4 stairs.


Image credit: rubygeiger.tumblr.com


The answer is 174.

This section requires Javascript.
You are seeing this because something didn't load right. We suggest you, (a) try refreshing the page, (b) enabling javascript if it is disabled on your browser and, finally, (c) loading the non-javascript version of this page . We're sorry about the hassle.

2 solutions

Geoff Pilling
Apr 5, 2016

For 1-6 stairs, you can quickly figure out that there are 0,1,1,1,2,2 ways respectively to get there. Now, to get to the n th n^\text{th} stair, he must have come from either stair n 2 n-2 , or n 3 n-3 (or n 2 \frac n2 if n n is even). So if f ( n ) f(n) is the number of ways he can climb to n stairs, then for n > 6 n>6 you can use this equation: f ( n ) = f ( n 3 ) + f ( n 2 ) f(n) = f(n-3) + f(n-2) for odd n n , and f ( n ) = f ( n 3 ) + f ( n 2 ) + f ( n / 2 ) f(n) = f(n-3) + f(n-2) + f(n/2) for even n n . So, for n = 20 n=20 , f ( n ) = 174 . f(n) =\boxed{174}.

Is it possible to find the general solution?

Calvin Lin Staff - 5 years, 2 months ago
1
2
3
4
5
6
7
8
int N = 20;
int c[] = new int[N+1];
c[0] = 1; c[1] = 0; c[2] = 1;

for (int i = 3; i <= N; i++)
    c[i] = c[i-2] + c[i-3] + ((i > 6 && i%2 == 0) ? c[i/2] : 0);

System.out.println(c[N]);

Output:

1
174

Very nice!

Geoff Pilling - 5 years, 2 months ago

0 pending reports

×

Problem Loading...

Note Loading...

Set Loading...