結果
| 問題 | 
                            No.90 品物の並び替え
                             | 
                    
| コンテスト | |
| ユーザー | 
                             bluemegane
                         | 
                    
| 提出日時 | 2020-09-07 07:21:33 | 
| 言語 | C#(csc)  (csc 3.9.0)  | 
                    
| 結果 | 
                             
                                AC
                                 
                             
                            
                         | 
                    
| 実行時間 | 1,937 ms / 5,000 ms | 
| コード長 | 1,834 bytes | 
| コンパイル時間 | 1,099 ms | 
| コンパイル使用メモリ | 117,796 KB | 
| 実行使用メモリ | 23,168 KB | 
| 最終ジャッジ日時 | 2024-11-29 10:12:40 | 
| 合計ジャッジ時間 | 4,659 ms | 
| 
                            ジャッジサーバーID (参考情報)  | 
                        judge4 / judge3 | 
(要ログイン)
| ファイルパターン | 結果 | 
|---|---|
| sample | AC * 1 | 
| other | AC * 9 | 
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc) Copyright (C) Microsoft Corporation. All rights reserved.
ソースコード
using System.Linq;
using System.Collections.Generic;
using static System.Math;
using System;
public static class Permi
{
    public static IEnumerable<IEnumerable<T>> Perm<T>(this IEnumerable<T> items, int? k = null)
    {
        if (k == null) k = items.Count();
        if (k == 0) yield return Enumerable.Empty<T>();
        else
        {
            var i = 0;
            foreach (var x in items)
            {
                var xs = items.Where((_, index) => i != index);
                foreach (var c in Perm(xs, k - 1))
                    yield return c.Before(x);
                i++;
            }
        }
    }
    public static IEnumerable<T> Before<T>(this IEnumerable<T> items, T first)
    {
        yield return first;
        foreach (var i in items) yield return i;
    }
}
public class Hello
{
    static void Main()
    {
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var m = int.Parse(line[1]);
        var r = new int[m, 3];
        for (int i = 0; i < m; i++)
        {
            line = Console.ReadLine().Trim().Split(' ');
            for (int j = 0; j < 3; j++)
                r[i, j] = int.Parse(line[j]);
        }
        getAns(n, m, r);
    }
    static int getPoint(int m, int[,] r, int[] c)
    {
        var res = 0;
        for (int i = 0; i < m; i++)
            if (c[r[i, 0]] < c[r[i, 1]]) res += r[i, 2];
        return res;
    }
    static void getAns(int n, int m, int[,] r)
    {
        var ans = 0;
        var a = Enumerable.Range(0, n).Perm();
        foreach (var x in a)
        {
            var b = x.ToArray();
            var c = new int[n];
            for (int i = 0; i < n; i++)
                c[b[i]] = i;
            ans = Max(ans, getPoint(m, r, c));
        }
        Console.WriteLine(ans);
    }
}
            
            
            
        
            
bluemegane