Submission #29388


ソースコード

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;
const LL inf = 1123456;
LL t, n;
std::vector<LL>m(1123), p(1123);
std::vector<std::vector<LL>>memo(1123, std::vector<LL>(1123, -1));
LL dp(LL b, LL s)
{
if (s < 0) { return -inf; }
if (b < 0) { return 0; }
if (memo[b][s] != -1) { return memo[b][s]; }
return memo[b][s] = std::max(dp(b - 1, s - m[b]) + p[b], dp(b - 1, s));
}
int main()
{
in >> t >> n;
rep(i, n) { in >> m[i] >> p[i]; }
out << dp(n - 1, t) << std::endl;
}

ステータス

項目 データ
問題 0170 - テスト勉強
ユーザー名 Bwambocos
投稿日時 2017-12-03 17:26:07
言語 C++17
状態 Accepted
得点 10
ソースコード長 586 Byte
最大実行時間 35 ms
最大メモリ使用量 10512 KB

セット

セット 得点 Cases
1 ALL 10 / 10 *

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
in1.txt AC 34 ms 10464 KB
1
in2.txt AC 28 ms 10380 KB
1
in3.txt AC 26 ms 10420 KB
1
in4.txt AC 19 ms 10456 KB
1
in5.txt AC 33 ms 10376 KB
1
in6.txt AC 26 ms 10420 KB
1
in7.txt AC 21 ms 10464 KB
1
in8.txt AC 23 ms 10384 KB
1
in9.txt AC 33 ms 10428 KB
1
in10.txt AC 35 ms 10512 KB
1