Maximize subsequences having array elements not exceeding length of the subsequence | C # program for the above approach ; Function to calculate the number of subsequences that can be formed ; Stores the number of subsequences ; Iterate over the map ; Count the number of subsequences that can be formed from x . first ; Number of occurrences of x . first which are left ; Return the number of subsequences ; Function to create the maximum count of subsequences that can be formed ; Stores the frequency of [ ] arr ; Update the frequency ; Print the number of subsequences ; Driver code ; Given array [ ] arr ; Function call
using System ; using System . Collections . Generic ; class GFG { public static int No_Of_subsequences ( Dictionary < int , int > mp ) { int count = 0 ; int left = 0 ; foreach ( KeyValuePair < int , int > x in mp ) { if ( ! mp . ContainsKey ( x . Key ) ) mp . Add ( x . Key , x . Value + left ) ; count += ( x . Value / x . Key ) ; left = x . Value % x . Key ; } return count ; } public static void maximumsubsequences ( int [ ] arr , int n ) { Dictionary < int , int > mp = new Dictionary < int , int > ( ) ; for ( int i = 0 ; i < n ; i ++ ) { if ( mp . ContainsKey ( arr [ i ] ) ) { mp [ arr [ i ] ] = mp [ arr [ i ] ] + 1 ; } else { mp . Add ( arr [ i ] , 1 ) ; } } Console . WriteLine ( No_Of_subsequences ( mp ) ) ; } public static void Main ( String [ ] args ) { int [ ] arr = { 1 , 1 , 1 , 1 } ; int N = arr . Length ; maximumsubsequences ( arr , N ) ; } }