| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 784705 | 0x34c | Knapsack (NOI18_knapsack) | C++17 | 1076 ms | 2764 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
int s, n;
cin >> s >> n;
int val[n], wei[n], mult[n];
for (int i = 0; i < n; i++)
cin >> val[i] >> wei[i] >> mult[i];
ll dp[2][s + 1];
int fr = 0, sc = 1;
dp[0][0] = 0;
for (int j = 1; j <= s; j++)
{
dp[0][j] = 0;
if (wei[0] <= j)
{
dp[0][j] = (ll)min(j / wei[0], mult[0]) * (ll)val[0];
}
}
for (int i = 1; i < n; i++)
{
for (int j = 0; j <= s; j++)
{
dp[sc][j] = dp[fr][j];
for (int m = 1; m <= mult[i] && j >= wei[i] * m; m++)
dp[sc][j] = max(dp[sc][j], dp[fr][j - wei[i] * m] + (ll)val[i] * (ll)m);
}
swap(fr, sc);
}
cout << dp[fr][s] << endl;
}| # | 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... | ||||
