| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1331330 | conthoanco | Knapsack (NOI18_knapsack) | C++20 | 45 ms | 17492 KiB |
#include <bits/stdc++.h>
using namespace std;
const int N = 2005;
int s, n, dp[N][N];
vector<pair<int,int>> group[N];
vector<int> val[N];
void input()
{
cin >> s >> n;
for(int i = 1; i <= n; ++i) {
int v, w, k;
cin >> v >> w >> k;
group[w].push_back({v, k});
}
}
void solve()
{
for(int w = 1; w <= s; ++w) {
sort(group[w].begin(), group[w].end(), greater<pair<int,int>>());
int cur = 0;
val[w].push_back(0);
for(int k = 1; k <= s / w; ++k) {
if(cur >= group[w].size()) break;
if(group[w][cur].second == 0) cur++;
if(cur >= group[w].size()) break;
val[w].push_back(val[w].back() + group[w][cur].first);
group[w][cur].second--;
}
}
memset(dp, -0x3f, sizeof(dp));
dp[0][0] = 0;
int ans = 0;
for(int w = 1; w <= s; ++w) {
for(int t = 0; t <= s; ++t) {
for(int k = 0; k <= t / w && k < val[w].size(); ++k) {
dp[w][t] = max(dp[w][t], dp[w - 1][t - w * k] + val[w][k]);
}
ans = max(ans, dp[w][t]);
}
}
cout << ans;
}
#undef int
int main()
{
if(fopen("trash.inp" , "r"))
freopen("trash.inp" , "r" , stdin) , freopen("trash.out" , "w" , stdout);
// else freopen(".inp" , "r" , stdin) , freopen(".out" , "w" , stdout);
ios::sync_with_stdio(0);
cin.tie(0);
int test = 1;
// cin >> test;
while(test--) {
input();
solve();
}
}
컴파일 시 표준 에러 (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... | ||||
