結果

問題 No.914 Omiyage
ユーザー tsushima
提出日時 2019-10-25 22:07:17
言語 C#(csc)
(csc 3.9.0)
結果
WA  
実行時間 -
コード長 1,191 bytes
コンパイル時間 2,221 ms
コンパイル使用メモリ 110,652 KB
実行使用メモリ 29,464 KB
最終ジャッジ日時 2024-09-13 03:58:41
合計ジャッジ時間 3,663 ms
ジャッジサーバーID
(参考情報)
judge1 / judge5
このコードへのチャレンジ
(要ログイン)
ファイルパターン 結果
sample AC * 2 WA * 1
other AC * 4 WA * 14
権限があれば一括ダウンロードができます
コンパイルメッセージ
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.Linq;
using System.Collections.Generic;

namespace Algorithm
{
    class Program
    {
        static int N, M, K;
        static int[][] A;
        static int[,] dp = new int[11, 501];
        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 = 0;
                if (dp[n, total] != 0) t = dp[n, total];
                else dp[n, total] = t = Dfs(n + 1, total + A[n][i]);
                max = Math.Max(max, t);
            }

            return max;
        }
    }
}
0