# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
713651 | PanosPask | Knapsack (NOI18_knapsack) | C++14 | 2 ms | 340 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define MAXN 100000
#define MAXS 2000
using namespace std;
struct item {
int copies;
int value;
int weight;
};
typedef struct item Item;
int latest[MAXS + 2];
int latest_val[MAXS + 2];
int used[MAXS + 2];
long long int bestval[MAXS + 2];
int n, s;
Item products[MAXN + 2];
int main(void)
{
scanf("%d %d", &n, &s);
for (int i = 0; i < n; i++)
scanf("%d %d %d", &products[i].value, &products[i].weight, &products[i].copies);
bestval[0] = 0;
for (int i = 0; i < n; i++) {
Item curitem = products[i];
memset(used, 0, sizeof(used));
for (int i = products[i].weight; i <= s; i++) {
if (used[i - curitem.weight] < curitem.copies) {
bestval[i] = bestval[latest[i]] + latest_val[i];
used[i] = used[latest[i]];
if (bestval[i - curitem.weight] + curitem.value > bestval[i]) {
used[i] = used[i - curitem.weight] + 1;
latest[i] = i - curitem.weight;
latest_val[i] = curitem.value;
bestval[i] = bestval[i - curitem.weight] + curitem.value;
}
}
}
}
for (int i = 0; i <= s; i++)
bestval[s] = max(bestval[s], bestval[i]);
printf("%lld\n", bestval[s]);
return 0;
}
컴파일 시 표준 에러 (stderr) 메시지
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|---|---|---|---|
Fetching results... |