結果

問題 No.914 Omiyage
ユーザー tsushimatsushima
提出日時 2019-10-25 22:00:48
言語 C#(csc)
(csc 3.9.0)
結果
TLE  
実行時間 -
コード長 1,090 bytes
コンパイル時間 1,541 ms
コンパイル使用メモリ 64,060 KB
実行使用メモリ 27,732 KB
最終ジャッジ日時 2023-10-11 04:12:18
合計ジャッジ時間 8,059 ms
ジャッジサーバーID
(参考情報)
judge15 / judge14
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 TLE -
testcase_01 -- -
testcase_02 -- -
testcase_03 -- -
testcase_04 -- -
testcase_05 -- -
testcase_06 -- -
testcase_07 -- -
testcase_08 -- -
testcase_09 -- -
testcase_10 -- -
testcase_11 -- -
testcase_12 -- -
testcase_13 -- -
testcase_14 -- -
testcase_15 -- -
testcase_16 -- -
testcase_17 -- -
testcase_18 -- -
testcase_19 -- -
testcase_20 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

using System;
using System.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static int N, M, K;
        static int[][] A;
        static int[,] dp = new int[11, 11];
        static void Main(string[] args)
        {
            var l = Console.ReadLine().Split().Select(int.Parse).ToArray();
            N = l[0];
            M = l[1];
            K = l[2];
            A = new int[N][];

            for (var i = 0; i < N; i++) A[i] = Console.ReadLine().Split().Select(int.Parse).ToArray();

            var ans = Dfs(0, 0);
            Console.WriteLine(ans == 0 ? -1 : K - ans);

        }

        static int Dfs(int n, int total)
        {
            if (total > K) return -1;

            if (n == N)
            {
                if (total <= K) return total;
                else return -1;
            }

            var max = 0;
            for (var i = 0; i < M; i++)
            {
                var t = Dfs(n + 1, total + A[n][i]);
                max = Math.Max(max, t);
            }

            return max;
        }
    }
}
0