Minimum count of numbers required from given array to represent S | C # implementation to find the minimum number of sequence required from array such that their sum is equal to given S ; Function to find the minimum elements required to get the sum of given value S ; Condition if the sequence is found ; Condition when no such sequence found ; Calling for without choosing the current index value ; Calling for after choosing the current index value ; Function for every array ; Driver code
using System ; using System . Collections . Generic ; class GFG { static int printAllSubsetsRec ( int [ ] arr , int n , List < int > v , int sum ) { if ( sum == 0 ) { return v . Count ; } if ( sum < 0 ) return Int32 . MaxValue ; if ( n == 0 ) return Int32 . MaxValue ; int x = printAllSubsetsRec ( arr , n - 1 , v , sum ) ; v . Add ( arr [ n - 1 ] ) ; int y = printAllSubsetsRec ( arr , n , v , sum - arr [ n - 1 ] ) ; v . RemoveAt ( v . Count - 1 ) ; return Math . Min ( x , y ) ; } static int printAllSubsets ( int [ ] arr , int n , int sum ) { List < int > v = new List < int > ( ) ; return printAllSubsetsRec ( arr , n , v , sum ) ; } static void Main ( ) { int [ ] arr = { 2 , 1 , 4 , 3 , 5 , 6 } ; int sum = 6 ; int n = arr . Length ; Console . WriteLine ( printAllSubsets ( arr , n , sum ) ) ; } }