Count lexicographically increasing K | C # program for the above approach ; Function to count K - length strings from first N alphabets ; To keep track of column sum in dp ; Auxiliary 2d dp array ; Initialize dp [ 0 ] [ i ] = 1 and update the column_sum ; Iterate for K times ; Iterate for N times ; dp [ i ] [ j ] : Stores the number of ways to form i - length strings consisting of j letters ; Update the column_sum ; Print number of ways to arrange K - length strings with N alphabets ; Driver Code ; Given N and K ; Function Call
using System ; class GFG { static void waysToArrangeKLengthStrings ( int N , int K ) { int [ ] column_sum = new int [ N + 1 ] ; int i , j ; for ( i = 1 ; i < N + 1 ; i ++ ) { column_sum [ i ] = 0 ; } int [ , ] dp = new int [ K + 1 , N + 1 ] ; for ( i = 1 ; i < K + 1 ; i ++ ) { for ( j = 1 ; j < N + 1 ; j ++ ) { dp [ i , j ] = 0 ; } } for ( i = 0 ; i <= N ; i ++ ) { dp [ 0 , i ] = 1 ; column_sum [ i ] = 1 ; } for ( i = 1 ; i <= K ; i ++ ) { for ( j = 1 ; j <= N ; j ++ ) { dp [ i , j ] += column_sum [ j - 1 ] ; column_sum [ j ] += dp [ i , j ] ; } } Console . Write ( dp [ K , N ] ) ; } public static void Main ( ) { int N = 5 , K = 2 ; waysToArrangeKLengthStrings ( N , K ) ; } }