結果

問題 No.269 見栄っ張りの募金活動
ユーザー simansiman
提出日時 2020-10-22 19:58:04
言語 Ruby
(3.3.0)
結果
AC  
実行時間 732 ms / 5,000 ms
コード長 367 bytes
コンパイル時間 383 ms
コンパイル使用メモリ 11,360 KB
実行使用メモリ 30,948 KB
最終ジャッジ日時 2023-09-28 14:47:59
合計ジャッジ時間 6,625 ms
ジャッジサーバーID
(参考情報)
judge13 / judge11
このコードへのチャレンジ
(要ログイン)

テストケース

テストケース表示
入力 結果 実行時間
実行使用メモリ
testcase_00 AC 86 ms
15,308 KB
testcase_01 AC 86 ms
15,108 KB
testcase_02 AC 92 ms
15,492 KB
testcase_03 AC 132 ms
16,304 KB
testcase_04 AC 325 ms
21,176 KB
testcase_05 AC 84 ms
15,072 KB
testcase_06 AC 84 ms
15,108 KB
testcase_07 AC 732 ms
30,948 KB
testcase_08 AC 85 ms
15,100 KB
testcase_09 AC 366 ms
22,132 KB
testcase_10 AC 85 ms
15,300 KB
testcase_11 AC 143 ms
16,760 KB
testcase_12 AC 302 ms
20,552 KB
testcase_13 AC 163 ms
17,252 KB
testcase_14 AC 93 ms
15,664 KB
testcase_15 AC 152 ms
17,200 KB
testcase_16 AC 284 ms
20,256 KB
testcase_17 AC 122 ms
16,412 KB
testcase_18 AC 483 ms
24,908 KB
testcase_19 AC 182 ms
17,792 KB
testcase_20 AC 97 ms
15,664 KB
testcase_21 AC 98 ms
15,772 KB
testcase_22 AC 132 ms
16,160 KB
testcase_23 AC 92 ms
15,304 KB
testcase_24 AC 103 ms
15,848 KB
権限があれば一括ダウンロードができます
コンパイルメッセージ
Syntax OK

ソースコード

diff #

N, S, K = gets.split.map(&:to_i)
MOD = 10 ** 9 + 7

dp = Array.new(N + 1) { Array.new(S + 1, 0) }

0.step(S, N) do |s|
  dp[0][s] = 1
end

1.upto(N - 1) do |i|
  0.upto(S) do |s|
    m = N - i

    if s >= K * m
      dp[i][s] += dp[i - 1][s - K * m]
    end

    if s - m >= 0
      dp[i][s] += dp[i][s - m]
    end

    dp[i][s] %= MOD
  end
end

puts dp[N - 1][S]
0