結果

問題 No.247 線形計画問題もどき
ユーザー te-shte-sh
提出日時 2017-05-25 16:04:52
言語 D
(dmd 2.106.1)
結果
TLE  
実行時間 -
コード長 553 bytes
コンパイル時間 616 ms
コンパイル使用メモリ 87,668 KB
実行使用メモリ 48,248 KB
最終ジャッジ日時 2023-09-03 13:34:23
合計ジャッジ時間 4,701 ms
ジャッジサーバーID
(参考情報)
judge11 / judge15
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 18 ms
22,628 KB
testcase_01 AC 1 ms
4,380 KB
testcase_02 TLE -
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 -- -
testcase_21 -- -
testcase_22 -- -
testcase_23 -- -
testcase_24 -- -
testcase_25 -- -
testcase_26 -- -
testcase_27 -- -
権限があれば一括ダウンロードができます

ソースコード

diff #

import std.algorithm, std.conv, std.range, std.stdio, std.string;

const inf = 10 ^^ 9;

void main()
{
  auto c = readln.chomp.to!int;
  auto n = readln.chomp.to!size_t;
  auto ai = readln.split.to!(int[]);

  auto dp = new int[][](n+1, c+1);
  foreach (ref d; dp) d[] = inf;
  dp[0][0] = 0;

  foreach (i; 0..n)
    foreach_reverse (j; 0..c+1)
      if (dp[i][j] < inf)
        foreach (k; 0..c) {
          auto l = k * ai[i] + j;
          if (l > c) break;
          dp[i+1][l] = min(dp[i+1][l], dp[i][j] + k);
        }

  writeln(dp[$-1][$-1]);
}
0