If already calculated
if ( dp [ mask ] [ prev ] [ col == 1 ] != 0 ) { return dp [ mask ] [ prev ] [ col == 1 ] ; } long long ans = 1e9 ; for ( int i = 0 ; i < n ; i ++ ) { for ( int j = 0 ; j < 2 ; j ++ ) {