run up
/*** 9.1
A child is running up a staircase with n steps, and can hop either 1 step, 2 steps
or 3 steps at atime. Implement a method to count how many possible ways the child can run up the stairs.
IDEA: n steps {1, 2, 3}
***/
#include<iostream>
using namespace std;
int runup(int n) {
if(n == 0) return 1;
if(n < 0) return 0;
return runup(n-1) + runup(n-2) + runup(n-3);
}
Comments
Post a Comment