# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1084021 | kitkat12 | Knapsack (NOI18_knapsack) | C++14 | 211 ms | 262144 KiB |
This submission is migrated from previous version of oj.uz, which used different machine for grading. This submission may have different result if resubmitted.
// https://oj.uz/problem/view/NOI18_knapsack
// Created on: 2024-09-04 21:21:52
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define mp make_pair
#define pb push_back
#define F first
#define S second
#define debug(x) std::cout << #x << ": " << x << "\n"
#define all(v) v.begin(), v.end()
#define li(i,a,b) for (int (i) = (a); (i) < (b); (i)++)
#define endl '\n'
#define mem(name,val) memset(name,val,sizeof(name))
#define min(a,b) (a<=b ? a : b)
#define max(a,b) (a>=b ? a : b)
//using u64 = uint64_t;
//using u128 = __uint128_t;
int main()
{
ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
int s,n;
cin>>s>>n;
int w[n], v[n], k[n];
li(i,0,n){
cin>>v[i]>>w[i]>>k[i];
}
int dp[s+2][n+2]; mem(dp,0);
for(int i = 1; i<=s; i++){
for(int j = 0; j<n ; j++){
for(int l = 0; l<=k[j]; l++){
if(j == 0){
if(i - w[j]*l >= 0){
dp[i][j] = max(dp[i][j], l * v[j]);
continue;
}
else{
break;
}
}
if(i - w[j]*l >= 0) dp[i][j] = max(dp[i][j], dp[i - w[j]*l][j-1] + l * v[j]);
else{
break;
}
}
}
}
cout<<dp[s][n-1];
return 0;
}
Compilation message (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... |