# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
482670 | Olympia | Knapsack (NOI18_knapsack) | C++17 | 2 ms | 972 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <cmath>
#include <iostream>
#include <set>
#include <climits>
#include <algorithm>
#include <cassert>
#include <vector>
#include <iomanip>
#include <type_traits>
#include <string>
#include <queue>
#include <map>
using namespace std;
#define ll long long
struct item {
int weight;
int worth;
};
int main() {
int S, N;
//S -> maximal weight; N -> number of items
cin >> S >> N;
vector<item> items;
for (int i = 0; i < N; i++) {
int wei, wor;
cin >> wei >> wor;
swap(wor, wei);
int cnt;
cin >> cnt;
for (int j = 0; j < min(S/(wei * cnt), cnt); j++) {
items.push_back({wei, wor});
}
}
int dp[items.size() + 1][S + 1]; //taking i items, what is the best worth that we can get
for (int i = 0; i < items.size() + 1; i++) {
for (int j = 0; j <= S; j++) {
dp[i][j] = 0;
}
}
for (int i = 1; i <= items.size(); i++) {
for (int j = 0; j <= S; j++) {
if (j - items[i - 1].weight >= 0) {
dp[i][j] = max(dp[i - 1][j - items[i - 1].weight] + items[i - 1].worth, dp[i - 1][j]);
}
}
}
cout << dp[items.size()][S] << 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... |