let ``No.90 品物の並び替え`` () = let rec insertions x = function | [] -> [[x]] | (y :: ys) as l -> (x::l)::(List.map (fun x -> y::x) (insertions x ys)) let rec permutations = function | [] -> seq [ [] ] | x :: xs -> Seq.concat (Seq.map (insertions x) (permutations xs)) let arr = stdin.ReadLine().Split(' ') let N = int arr.[0] let M = int arr.[1] let score = List.init N (fun _ -> Array.init N (fun _ -> 0)) seq { for i in 1..M -> Array.map int (stdin.ReadLine().Split(' ')) } |> Seq.take M |> Seq.iter (fun a -> score.[a.[0]].[a.[1]] <- a.[2]) permutations [0..(N-1)] |> Seq.map (fun m -> Seq.sum <| seq { for a in 0..(N-1) do for b in (a+1)..(N-1) -> score.[m.[a]].[m.[b]] }) |> Seq.max |> (printfn "%d") ``No.90 品物の並び替え`` ()