# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
659008 | kuderRahul | Knapsack (NOI18_knapsack) | C++14 | 1 ms | 468 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;
#define int long long int
#define v vector
const int N = 1e6 + 111, mod = 1e9 + 7;
void solve() {
int n,s,a,b,c;
cin>>s>>n;
if(n==1){
cin>>a>>b>>c;
cout<<min(s/b,c)*a<<'\n';
return;
}
v<int>weight(n+1),value(n+1),itemCount(n+1,1);
for(int i=0;i<n;i++)cin>>value[i]>>weight[i]>>itemCount[i];
v<v<int>>dp(n+11,v<int>(s+11,0));
for(int i=0;i<=n;i++)dp[0][i]=0;
for(int i=1;i<=n;i++)
for(int j=1;j<=s;j++)
for(int x=0;x<=itemCount[i-1];x++)
if(j-x*weight[i-1]>=0)dp[i][j]=max(dp[i][j],value[i-1]*x+dp[i-1][j-x*weight[i-1]]);
cout<<dp[n][s];
}
signed main() {
freopen("input.txt", "r", stdin);
freopen("output.txt", "w", stdout);
// int t;scanf("%lld",&t);while(t--)
solve();
}
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... |