# | TimeUTC-0 | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
857159 | neodoomer | Knapsack (NOI18_knapsack) | C++14 | 154 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.
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
#define pi pair<int,int>
int s;
int knapsack ( vector<pair<ll,ll> >& vw ){
int n=vw.size();
ll dp[n+1][s+1];
for(int i=0;i<=n;i++)
for(int w=0;w<=s;w++)
dp[i][w]=-1e18;
ll ans=0;
dp[0][0]=0;
for(int i=1;i<=n;i++)
{
for(int w=0;w<=s;w++)
{
dp[i][w]=dp[i-1][w];
if(w-vw[i-1].S>=0)
dp[i][w]=max(dp[i][w],dp[i-1][w-vw[i-1].S]+vw[i-1].F);
ans=max(ans,dp[i][w]);
}
}
return ans;
}
int main()
{
# | 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... |