title: Total Number Of Non Decreasing Numbers With N Digits
signature: total_number_of_non_decreasing_numbers_with_n_digits <- function(n) {
test_code: 
  
  
  # SOLUTION CODE
  # ============================================
  PLACEHOLDER_CODE_BODY
  
  # TESTING CODE 
  # ============================================
  validate_solution <- function(actual, expected) {
      toString(actual)==toString(expected)
  }
  
  driver <- function(n, expected){
      if (validate_solution(PLACEHOLDER_FN_NAME(n), expected)){
          "PASSED"
      } else{
          "FAILED"
      }
  }
  
  main <- function() {
      cat(sprintf("TEST-0...%s\n",driver(
          21L, 
          14307150L
      )))
  
      cat(sprintf("TEST-1...%s\n",driver(
          40L, 
          2054455634L
      )))
  
      cat(sprintf("TEST-2...%s\n",driver(
          83L, 
          868754947060L
      )))
  
      cat(sprintf("TEST-3...%s\n",driver(
          93L, 
          2290415157800L
      )))
  
      cat(sprintf("TEST-4...%s\n",driver(
          43L, 
          3679075400L
      )))
  
      cat(sprintf("TEST-5...%s\n",driver(
          98L, 
          3585446225075L
      )))
  
      cat(sprintf("TEST-6...%s\n",driver(
          35L, 
          708930508L
      )))
  
      cat(sprintf("TEST-7...%s\n",driver(
          86L, 
          1174992339235L
      )))
  
      cat(sprintf("TEST-8...%s\n",driver(
          76L, 
          411731930610L
      )))
  
      cat(sprintf("TEST-9...%s\n",driver(
          88L, 
          1429144287220L
      )))
  
  }
  
  main()
source_py: def total_number_of_non_decreasing_numbers_with_n_digits(n):
      dp = [[0 for i in range((n + 1))] for i in range(10)]
      for i in range(10):
          dp[i][1] = 1
      for digit in range(10):
          for len in range(2, (n + 1)):
              for x in range((digit + 1)):
                  dp[digit][len] += dp[x][(len - 1)]
      count = 0
      for i in range(10):
          count += dp[i][n]
      return count
source_cpp: long long int total_number_of_non_decreasing_numbers_with_n_digits(int n) {
    long long int dp [ 10 ] [ n + 1 ];
    memset ( dp, 0, sizeof dp );
    for ( int i = 0;
    i < 10;
    i ++ ) dp [ i ] [ 1 ] = 1;
    for ( int digit = 0;
    digit <= 9;
    digit ++ ) {
      for ( int len = 2;
      len <= n;
      len ++ ) {
        for ( int x = 0;
        x <= digit;
        x ++ ) dp [ digit ] [ len ] += dp [ x ] [ len - 1 ];
      }
    }
    long long int count = 0;
    for ( int i = 0;
    i < 10;
    i ++ ) count += dp [ i ] [ n ];
    return count;
  }