- Dynamic Programming, Mathematical, number-digits, Recursion

Count N-digit numbers whose digits does not exceed absolute difference of the two previous digits

  #include using namespace std;  long long dp[50][10][10];  long long countOfNumbers(int digit, int prev1,                         int prev2, int N){        if (digit == N + 1)        return 1;          if (dp[digit][prev1][prev2] != -1)        return dp[digit][prev1][prev2];      dp[digit][prev1][prev2] = 0;                  if (digit == 1) {        for (int j = (N == 1 ? 0 : 1);             j