# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
484006 | T0p_ | Knapsack (NOI18_knapsack) | C++14 | 1 ms | 204 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.
#include <bits/stdc++.h>
using namespace std;
long long dp[2][2005];
int main()
{
int s, n;
scanf(" %d %d",&s,&n);
for(int i=1 ; i<=n ; i++)
{
for(int j=1 ; j<=s ; j++) dp[i%2][j] = 0;
int w, k;
long long v;
scanf(" %lld %d %d",&v,&w,&k);
for(int j=1 ; j<=s ; j++)
{
dp[i%2][j] = dp[i%2][j-1];
for(int t=1 ; t<=k && j-w*t>=0 ; t++) dp[i%2][j] = max(dp[i%2][j], dp[(i-1)%2][j-w*t] + v*t);
}
}
printf("%lld\n",dp[n%2][s]);
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... |