| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 755534 | 3omar_ahmed | Knapsack (NOI18_knapsack) | C++17 | 6 ms | 12244 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
/**
* author: 3omar_ahmed
* date: 09-06-2023
* ya rb awsl CM :)
*/
#include <bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std ;
#define int long long
#define endl '\n'
#define all(a) a.begin() , a.end()
#define alr(a) a.rbegin() , a.rend()
int x, n;
vector < vector < int >> dp;
vector < vector < pair < int , int >>> a;
int DP(int idx, int still) {
if(still == 0 || idx == n) return 0;
if(dp[idx][still] != -1) return dp[idx][still];
int op1 = DP(idx + 1, still);
int op2 = 0, sum = 0, val = 0;
for(int i = 0 ; i < a[idx].size() ; i++) {
for(int j = 0 ; j < a[idx][i].second ; j++) {
sum += idx + 1, val += a[idx][i].first;
if(sum > still) break;
op2 = max(op2, DP(idx + 1, still - sum) + val);
}
}
return dp[idx][still] = max(op1, op2);
}
signed main(){
ios_base::sync_with_stdio(0); cin.tie(0);cout.tie(0);
cin >> x >> n;
a = vector < vector < pair < int , int >>> (x + 1);
for(int i = 0 ; i < n ; i++) {
int b, c, d;
cin >> b >> c >> d;
a[c - 1].push_back({b, d});
}
dp = vector < vector < int >> (x + 2, vector < int > (x + 2, -1));
for(auto &i : a) sort(alr(i));
cout << DP(0, x) << endl;
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... | ||||
