Finding a cut such that first l elements can be partitioned into j - 1 ' good ' segments and arr [ l + 1 ] + ... + arr [ i ] is a ' good ' segment
for l in range ( i - 1 , - 1 , - 1 ) : NEW_LINE INDENT if ( dp [ l ] [ j - 1 ] and ( ( ( prefix [ i ] - prefix [ l ] ) & mask ) == mask ) ) : NEW_LINE INDENT dp [ i ] [ j ] = 1 NEW_LINE break NEW_LINE DEDENT DEDENT return dp [ n ] [ k ] NEW_LINE