| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 966892 | Jomnoi | Knapsack (NOI18_knapsack) | C++17 | 215 ms | 19540 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
const int MAX_W = 2005;
int dp[MAX_W][MAX_W];
vector <pair <int, int>> items[MAX_W];
int main() {
cin.tie(nullptr)->sync_with_stdio(false);
int S, N;
cin >> S >> N;
while (N--) {
int v, w, k;
cin >> v >> w >> k;
items[w].emplace_back(v, k);
}
for (int w = 1; w <= S; w++) sort(items[w].begin(), items[w].end(), greater <pair <int, int>> ());
for (int i = 1; i <= S; i++) {
for (int w = 0; w <= S; w++) {
int cur_w = w, cur_v = 0;
dp[i][w] = dp[i - 1][w];
for (auto [v, k] : items[i]) {
int cur_k = k;
while (cur_w - i >= 0 and cur_k > 0) {
dp[i][w] = max(dp[i][w], dp[i - 1][cur_w - i] + cur_v + v);
cur_v += v;
cur_w -= i;
cur_k--;
}
}
}
}
cout << dp[S][S];
return 0;
}| # | 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... | ||||
