title: Total Number Of Non Decreasing Numbers With N Digits
signature: class Solution {
  
      public long TotalNumberOfNonDecreasingNumbersWithNDigits(int n) {
test_code: using System;
  using System.Numerics;
  using System.Diagnostics;
  using System.Collections.Generic;
  using System.Linq;
  using System.Text;
  using System.Security.Cryptography;
  using System.Web.UI;
  using System.Web.Script.Serialization;
  
  // SOLUTION CODE
  // ============================================
  PLACEHOLDER_CODE_BODY
  
  // TESTING CODE 
  // ============================================
  namespace EvaluatePrediction {
      class TestRunner {
          public bool ValidateSolution(long actual, long expected){
              return new JavaScriptSerializer().Serialize(actual) == new JavaScriptSerializer().Serialize(expected);
          }
  
          public string driver(int n, long expected){
              try{
                PLACEHOLDER_CLS_NAME solution_cls = new PLACEHOLDER_CLS_NAME();
                long pred_result = solution_cls.PLACEHOLDER_FN_NAME(n); 
                if (ValidateSolution(
                      pred_result,
                      expected)){
                  return "PASSED";
                }
                return "FAILED";
              } 
              catch (Exception exception_obj)
              {
                return exception_obj.GetType().FullName;
              }
          }
          static void Main(string[] args) {
              TestRunner runner = new TestRunner();
              String result;
              result = runner.driver(
                  21, 
                  14307150
              );
              Console.WriteLine(string.Format(
                  "TEST-0...{0}",
                  result)
              );result = runner.driver(
                  40, 
                  2054455634
              );
              Console.WriteLine(string.Format(
                  "TEST-1...{0}",
                  result)
              );result = runner.driver(
                  83, 
                  868754947060
              );
              Console.WriteLine(string.Format(
                  "TEST-2...{0}",
                  result)
              );result = runner.driver(
                  93, 
                  2290415157800
              );
              Console.WriteLine(string.Format(
                  "TEST-3...{0}",
                  result)
              );result = runner.driver(
                  43, 
                  3679075400
              );
              Console.WriteLine(string.Format(
                  "TEST-4...{0}",
                  result)
              );result = runner.driver(
                  98, 
                  3585446225075
              );
              Console.WriteLine(string.Format(
                  "TEST-5...{0}",
                  result)
              );result = runner.driver(
                  35, 
                  708930508
              );
              Console.WriteLine(string.Format(
                  "TEST-6...{0}",
                  result)
              );result = runner.driver(
                  86, 
                  1174992339235
              );
              Console.WriteLine(string.Format(
                  "TEST-7...{0}",
                  result)
              );result = runner.driver(
                  76, 
                  411731930610
              );
              Console.WriteLine(string.Format(
                  "TEST-8...{0}",
                  result)
              );result = runner.driver(
                  88, 
                  1429144287220
              );
              Console.WriteLine(string.Format(
                  "TEST-9...{0}",
                  result)
              );
          }
      }
  }
  
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;
  }