| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 861329 | anarch_y | Knapsack (NOI18_knapsack) | C++17 | 222 ms | 262144 KiB |
이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define all(x) begin(x), end(x)
#define pb push_back
#define int long long
signed main(){
ios::sync_with_stdio(false);
cin.tie(nullptr);
int S, N; cin >> S >> N;
vector<int> V(N+1, 0), W(N+1, 0), K(N+1, 0);
for(int i=1; i<=N; i++){
cin >> V[i] >> W[i] >> K[i];
K[i] = min(K[i], S/W[i]);
}
int dp[N+1][S+1] = {};
for(int i=1; i<=N; i++){
for(int j=1; j<=S; j++){
dp[i][j] = dp[i-1][j];
for(int k=1; k<=K[i]; k++){
int w = k*W[i];
if(j>=w){
dp[i][j] = max(dp[i][j], dp[i-1][j-w]+k*V[i]);
}
}
}
}
cout << dp[N][S];
} | # | 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... | ||||
