Submission #00081


ソースコード

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
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <bits/stdc++.h>
using namespace std;
int n, m;
int w[400];
int ans[400];
int memo[400][400][400];
bool flag = false;
typedef struct {
int s, l, p;
} meldy;
meldy a[555];
int dfs(int now, int dust, int cnt)
{
int ret = 0;
if (now == n || dust == 0) return 0;
if (memo[now][dust][cnt] != -1) return memo[now][dust][cnt];
if (dust - a[now].s >= 0) {
for (int i = a[now].s; i < a[now].l; i++) {
if (dust - i < 0) break;
ret = max(ret, dfs(now+1, dust-i, cnt+1) + a[now].p);
}
}
return memo[now][dust][cnt] = max(ret, dfs(now+1, dust, cnt));
}
int main()
{
cin >> n;
memset(memo, -1, sizeof(memo));
for (int i = 0; i < n; i++) {
cin >> a[i].s >> a[i].l >> a[i].p;
}
cin >> m;
for (int i = 0; i < m; i++) {
cin >> w[i];
ans[i] = dfs(0, w[i], 0);
if (ans[i] == 0) flag = true;
}
if (flag == true) cout << "-1" << endl;
else {
for (int i = 0; i < m; i++) {
cout << ans[i] << endl;
}
}
}

ステータス

項目 データ
問題 0004 - VOCAL ANDROID
ユーザー名 udonkun
投稿日時 2016-08-12 11:33:13
言語 C++11
状態 Memory Limit Exceeded
得点 0
ソースコード長 1044 Byte
最大実行時間 1000 ms
最大メモリ使用量 65536 KB

セット

セット 得点 Cases
1 ALL 0 / 9 *

テストケース

ファイル名 状態 実行時間 メモリ使用量 #
2502-in1.txt MLE 1000 ms 65536 KB
1
2502-in2.txt MLE 1000 ms 65536 KB
1
2502-in3.txt MLE 1000 ms 65536 KB
1
2502-in4.txt MLE 1000 ms 65536 KB
1
2502-in5.txt MLE 1000 ms 65536 KB
1
2502-in6.txt MLE 1000 ms 65536 KB
1
2502-in7.txt MLE 1000 ms 65536 KB
1
2502-in8.txt MLE 1000 ms 65536 KB
1
2502-in9.txt MLE 1000 ms 65536 KB
1
2502-in10.txt MLE 1000 ms 65536 KB
1
2502-in11.txt MLE 1000 ms 65536 KB
1
2502-in12.txt MLE 1000 ms 65536 KB
1
2502-in13.txt MLE 1000 ms 65536 KB
1
2502-in14.txt MLE 1000 ms 65536 KB
1
2502-in15.txt MLE 1000 ms 65536 KB
1
2502-in16.txt MLE 1000 ms 65536 KB
1
2502-in17.txt MLE 1000 ms 65536 KB
1
2502-in18.txt MLE 1000 ms 65536 KB
1
2502-in19.txt MLE 1000 ms 65536 KB
1
2502-in20.txt MLE 1000 ms 65536 KB
1
2502-in21.txt MLE 1000 ms 65536 KB
1
2502-in22.txt MLE 1000 ms 65536 KB
1
2502-in23.txt MLE 1000 ms 65536 KB
1