def ascan; gets.split.map(&:to_i);end N,M = ascan score = Hash.new(0) M.times do i,j,x = ascan score[[i,j]] = x end NP = 1<< N dp = Array.new(NP, 0) 0.upto(NP-2) do |b| N.times do |i| next if b & (1<< i) != 0 t = (0...N).map{|j| b & (1<< j) == 0 ? 0 : score[[j,i]]}.reduce(:+) dp[b | (1<< i)] = [dp[b | (1<< i)], dp[b]+t].max end end p dp[NP-1]