結果

問題 No.357 品物の並び替え (Middle)
ユーザー mbanmban
提出日時 2018-06-19 23:24:52
言語 C#(csc)
(csc 3.9.0)
結果
AC  
実行時間 68 ms / 5,000 ms
コード長 3,263 bytes
コンパイル時間 3,368 ms
コンパイル使用メモリ 102,856 KB
実行使用メモリ 22,904 KB
最終ジャッジ日時 2023-09-13 07:14:29
合計ジャッジ時間 5,003 ms
ジャッジサーバーID
(参考情報)
judge15 / judge13
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 55 ms
18,828 KB
testcase_01 AC 56 ms
20,840 KB
testcase_02 AC 56 ms
22,904 KB
testcase_03 AC 56 ms
20,740 KB
testcase_04 AC 56 ms
22,780 KB
testcase_05 AC 56 ms
20,684 KB
testcase_06 AC 58 ms
20,676 KB
testcase_07 AC 55 ms
18,708 KB
testcase_08 AC 56 ms
22,760 KB
testcase_09 AC 61 ms
20,796 KB
testcase_10 AC 57 ms
20,728 KB
testcase_11 AC 56 ms
20,868 KB
testcase_12 AC 68 ms
18,832 KB
testcase_13 AC 63 ms
22,812 KB
testcase_14 AC 62 ms
20,916 KB
testcase_15 AC 58 ms
22,764 KB
testcase_16 AC 59 ms
20,932 KB
testcase_17 AC 57 ms
20,940 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Microsoft (R) Visual C# Compiler version 3.9.0-6.21124.20 (db94f4cc)
Copyright (C) Microsoft Corporation. All rights reserved.

ソースコード

diff #

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;
using System.Runtime.Remoting.Contexts;

namespace Contest
{
    class Scanner
    {
        private string[] line = new string[0];
        private int index = 0;

        public string Next()
        {
            if (line.Length <= index)
            {
                line = Console.ReadLine().Split(' ');
                index = 0;
            }

            var res = line[index];
            index++;
            return res;
        }

        public int NextInt()
        {
            return int.Parse(Next());
        }

        public long NextLong()
        {
            return long.Parse(Next());
        }

        public string[] Array()
        {
            line = Console.ReadLine().Split(' ');
            index = line.Length;
            return line;
        }

        public int[] IntArray(int n)
        {
            var array = Array();
            var result = new int[n];
            for (int i = 0; i < n; i++)
            {
                result[i] = int.Parse(array[i]);
            }

            return result;
        }

        public int[] IntArray()
        {
            var array = Array();
            var result = new int[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                result[i] = int.Parse(array[i]);
            }

            return result;
        }


        public long[] LongArray()
        {
            var array = Array();
            var result = new long[array.Length];
            for (int i = 0; i < array.Length; i++)
            {
                result[i] = long.Parse(array[i]);
            }

            return result;
        }

        public uint NextUint()
        {
            return uint.Parse(Next());
        }
    }

    class Program
    {
        private int N, M;
        private int[,] Score;
        private void Scan()
        {
            var sc = new Scanner();
            N = sc.NextInt();
            M = sc.NextInt();
            Score = new int[N, N];
            for (int i = 0; i < M; i++)
            {
                int item1 = sc.NextInt();
                int item2 = sc.NextInt();
                int score = sc.NextInt();
                Score[item1, item2] = score;
            }
        }


        public void Solve()
        {
            Scan();
            int max = 1 << N;
            long[] dp = new long[max];
            for (int i = 0; i < max; i++)
            {
                for (int j = 0; j < N; j++)
                {
                    int k = 1 << j;
                    if ((i & k) == 0)
                    {
                        long sum = dp[i];
                        for (int l = 0; l < N; l++)
                        {
                            int p = 1 << l;
                            if ((i & p) != 0)
                            {
                                sum += Score[l, j];
                            }

                        }

                        dp[i + k] = Math.Max(dp[i + k], sum);
                    }
                }
            }
            Console.WriteLine(dp[max - 1]);
        }

        static void Main() => new Program().Solve();
    }
}
0