# | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
---|---|---|---|---|---|---|---|
845037 | taimoitapcode1 | Knapsack (NOI18_knapsack) | C++17 | 108 ms | 35152 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define ll long long
ll oo = 1e18 + 7, res = 0;
int limit, n;
vector<pair<int, int>> weight[2005];
ll dp[2005][2005];
int main(){
cin >> limit >> n;
for (int i = 1; i <= n; i++){
int weigh, value, cnt;
cin >> value >> weigh >> cnt;
weight[weigh].push_back({value, cnt});
}
for (int i = 1; i <= limit; i++) sort(weight[i].begin(), weight[i].end(), greater<pair<int, int>>());
for (int i = 0; i <= limit; i++){
for (int cost = 0; cost <= limit; cost++) dp[i][cost] = -oo;
}
dp[0][0] = 0;
for (int i = 1; i <= limit; i++){
for (int cost = 0; cost <= limit; cost++){
int index = 0;
int cnt = 1;
int typee = 0;
ll hihi = 0;
dp[i][cost] = dp[i - 1][cost];
while(cnt * i <= cost && typee < weight[i].size()){
hihi += weight[i][typee].fi;
if(dp[i - 1][cost - cnt * i] != oo) dp[i][cost] = max(dp[i][cost], dp[i - 1][cost - cnt * i] + hihi);
res = max(res, dp[i][cost]);
index++;
cnt++;
if(index == weight[i][typee].se){
index = 0;
typee++;
}
}
}
}
cout << res;
}
컴파일 시 표준 에러 (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... |