| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1319325 | quan123 | Knapsack (NOI18_knapsack) | C++20 | 1095 ms | 456 KiB |
#include <bits/stdc++.h>
#define int long long
using namespace std;
template<typename T, typename... Args>
void print(T t) {cout << t << '\n';}
template<typename T, typename... Args>
void print(T t, Args... args) {cout << t << " "; print(args...) ;}
const int S = 2005 , MX = 1e9+7;
int dp[S];
int n , s , ans = -MX;
vector<int> gen(int k) {
vector<int> ans;
int sm = k;
for (int p = 0; (k>>p) != 1; p++) {
ans.push_back(1<<p);
sm -= (1<<p);
}
ans.push_back(sm);
return ans;
}
void file_input() {
if (fopen("inp.txt" , "r")) {
freopen("inp.txt" , "r" , stdin);
freopen("out.txt" , "w" , stdout);
}
}
signed main() {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
file_input();
for (int i = 1; i < S; i++) {dp[i] = -1;}
cin >> s >> n;
while (n--) {
int a , b , k;
cin >> a >> b >> k;
vector<int> l = gen(k);
for (int i : l) {
int v = a*i , w = b*i;
for (int p = s-w; p >= 0; p--) {
if (dp[p] == -1) {continue;}
dp[p+w] = max(dp[p+w] , dp[p]+v);
}
}
}
for (int p = 0; p <= s; p++) {ans = max(ans , dp[p]);}
cout << ans;
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... | ||||
