Number of shortest paths to reach every cell from bottom | CPP program to find number of shortest paths ; Function to find number of shortest paths ; Compute the grid starting from the bottom - left corner ; Print the grid ; Driver code ; Function call
#include <bits/stdc++.h> NEW_LINE using namespace std ; void NumberOfShortestPaths ( int n , int m ) { int a [ n ] [ m ] ; for ( int i = 0 ; i < n ; i ++ ) memset ( a [ i ] , 0 , sizeof ( a [ i ] ) ) ; for ( int i = n - 1 ; i >= 0 ; i -- ) { for ( int j = 0 ; j < m ; j ++ ) { if ( j == 0 or i == n - 1 ) a [ i ] [ j ] = 1 ; else a [ i ] [ j ] = a [ i ] [ j - 1 ] + a [ i + 1 ] [ j ] ; } } for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < m ; j ++ ) { cout << a [ i ] [ j ] << " ▁ " ; } cout << endl ; } } int main ( ) { int n = 5 , m = 2 ; NumberOfShortestPaths ( n , m ) ; return 0 ; }