Minimum count of numbers required from given array to represent S | Function to find the count of minimum length of the sequence ; Loop to initialize the array as infinite in the row 0 ; Loop to find the solution by pre - computation for the sequence ; Minimum possible for the previous minimum value of the sequence ; Driver Code
def Count ( S , m , n ) : NEW_LINE INDENT table = [ [ 0 for i in range ( n + 1 ) ] for i in range ( m + 1 ) ] NEW_LINE for i in range ( 1 , n + 1 ) : NEW_LINE INDENT table [ 0 ] [ i ] = 10 ** 9 - 1 NEW_LINE DEDENT for i in range ( 1 , m + 1 ) : NEW_LINE INDENT for j in range ( 1 , n + 1 ) : NEW_LINE INDENT if ( S [ i - 1 ] > j ) : NEW_LINE INDENT table [ i ] [ j ] = table [ i - 1 ] [ j ] NEW_LINE DEDENT else : NEW_LINE INDENT table [ i ] [ j ] = min ( table [ i - 1 ] [ j ] , table [ i ] [ j - S [ i - 1 ] ] + 1 ) NEW_LINE DEDENT DEDENT DEDENT return table [ m ] [ n ] NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT arr = [ 9 , 6 , 5 , 1 ] NEW_LINE m = len ( arr ) NEW_LINE print ( Count ( arr , m , 11 ) ) NEW_LINE DEDENT