(defun f (b n dp scores) (if (/= -1 (aref dp b)) (aref dp b) (let ((m 0)) (dotimes (i n) (unless (zerop (logand 1 (ash b (- i)))) (let ((s (f (logxor b (ash 1 i)) n dp scores))) (dotimes (j n) (incf s (* (logand 1 (ash b (- j))) (aref scores (+ j (* i n)))))) (setf m (max m s))))) (setf (aref dp b) m) m))) (defun main (&rest argv) (declare (ignorable argv)) (let* ((n (read)) (m (read)) (scores (make-array (* n n))) (dp (make-array (ash 1 n) :element-type 'integer :initial-element -1)) (res 0)) (dotimes (i m) (let* ((item1 (read)) (item2 (read)) (score (read))) (setf (aref scores (+ (* item1 n) item2)) score))) (setf (aref dp 0) 0) (setq res (f (1- (ash 1 n)) n dp scores)) (format t "~d~%" res))) (main)