Minimum number of days to debug all programs | Python 3 program for the above approach ; Function to calculate the minimum work sessions ; Break condition ; All bits are set ; Check if already calculated ; Store the answer ; Check if ith bit is set or unset ; Including in current work session ; Including in next work session ; Resultant answer will be minimum of both ; Function to initialize DP array and solve the problem ; Initialize dp table with - 1 ; Resultant mask ; no . of minimum work sessions is even ; no . of minimum work sessions is odd ; Driver code
import sys NEW_LINE def minSessions ( codeTime , dp , ones , n , mask , currTime , WorkingSessionTime ) : NEW_LINE INDENT if ( currTime > WorkingSessionTime ) : NEW_LINE INDENT return sys . maxsize NEW_LINE DEDENT if ( mask == ones ) : NEW_LINE INDENT return 1 NEW_LINE DEDENT if ( dp [ mask ] [ currTime ] != - 1 ) : NEW_LINE INDENT return dp [ mask ] [ currTime ] NEW_LINE DEDENT ans = sys . maxsize NEW_LINE for i in range ( n ) : NEW_LINE INDENT if ( ( mask & ( 1 << i ) ) == 0 ) : NEW_LINE INDENT inc = minSessions ( codeTime , dp , ones , n , mask | ( 1 << i ) , currTime + codeTime [ i ] , WorkingSessionTime ) NEW_LINE inc_next = 1 + minSessions ( codeTime , dp , ones , n , mask | ( 1 << i ) , codeTime [ i ] , WorkingSessionTime ) NEW_LINE ans = min ( [ ans , inc , inc_next ] ) NEW_LINE DEDENT DEDENT dp [ mask ] [ currTime ] = ans NEW_LINE return ans NEW_LINE DEDENT def solve ( codeTime , n , WorkingSessionTime ) : NEW_LINE INDENT dp = [ [ - 1 for i in range ( 15 ) ] for j in range ( 1 << 14 ) ] NEW_LINE ones = ( 1 << n ) - 1 NEW_LINE ans = minSessions ( codeTime , dp , ones , n , 0 , 0 , WorkingSessionTime ) NEW_LINE if ( WorkingSessionTime < 6 ) : NEW_LINE INDENT if ( ans % 2 == 0 ) : NEW_LINE INDENT ans = ans // 2 NEW_LINE DEDENT else : NEW_LINE INDENT ans = ( ans / 2 ) + 1 NEW_LINE DEDENT DEDENT return int ( ans ) NEW_LINE DEDENT if __name__ == ' _ _ main _ _ ' : NEW_LINE INDENT codeTime = [ 1 , 2 , 3 , 1 , 1 , 3 ] NEW_LINE n = len ( codeTime ) NEW_LINE WorkingSessionTime = 4 NEW_LINE print ( solve ( codeTime , n , WorkingSessionTime ) ) NEW_LINE DEDENT