| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 630603 | chjiao | Knapsack (NOI18_knapsack) | C++14 | 1089 ms | 5812 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define ll long long
int main() {
ios_base::sync_with_stdio(false); cin.tie(NULL);
// freopen("Knapsack.in", "r", stdin);
// freopen("Knapsack.out", "w", stdout);
int limit, type_num;
cin >> limit >> type_num;
vector<vector<int>> items(type_num, vector<int>(3));
for (int i = 0; i < type_num; i++) {
int weight, num, val;
cin >> val >> weight >> num;
if (weight>limit) continue;
items[i][0] = weight; items[i][1] = num; items[i][2] = val;
}
vector<int> dp(limit+1, -1);
dp[0]= 0;
int dylimit = 0;
for (int t=0; t<items.size(); t++) {
int weight, num, val;
weight = items[t][0]; num = items[t][1]; val = items[t][2];
for (int i= dylimit; i>=0; i--) {
if (dp[i]>=0) {
for (int k=1; k <= num && i+weight*k <= limit; k++) {
dp[i+weight*k] = max(dp[i+weight*k], dp[i] + k*val);
dylimit = max(dylimit, i+weight*k);
}
}
}
}
cout << *max_element(dp.begin(), dp.end()) << endl;
}
컴파일 시 표준 에러 (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... | ||||
