Function to find the minimum number of elements in a sorted array A [ i . . j ] such that their sum is N
def minimumSubsetSize ( A , i , j , N ) : NEW_LINE INDENT if ( not N ) : NEW_LINE INDENT return 0 NEW_LINE DEDENT if ( i > j or A [ i ] > N ) : NEW_LINE INDENT return 10 ** 9 NEW_LINE DEDENT if ( dp [ i ] [ N ] ) : NEW_LINE INDENT return dp [ i ] [ N ] NEW_LINE DEDENT dp [ i ] [ N ] = min ( 1 + minimumSubsetSize ( A , i + 1 , j , N - A [ i ] ) , minimumSubsetSize ( A , i + 1 , j , N ) ) NEW_LINE return dp [ i ] [ N ] NEW_LINE DEDENT