# | Time | Username | Problem | Language | Result | Execution time | Memory |
---|---|---|---|---|---|---|---|
1092400 | iloveroseanne | Knapsack (NOI18_knapsack) | C++14 | 20 ms | 6492 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.
/// PARK CHAEYOUNG IS MY LOVE
/// Author: Ngo Ba Van
/// roses_are_rosie
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define fi first
#define se second
#define MASK(i) (1LL<<i)
#define BIT(x,i) (x&MASK(i))
#define ONBIT(x,i) (x|MASK(i))
#define OFFBIT(x,i) (x&~MASK(i))
#define COUNT(x) (__builtin_popcount(x))
#define RVAN1102 signed main()
using ii=pair<int,int>;
const ll N=1e5+5,M=1e9+7;
ll n,m,res,dp[N][2005];
vector<ii>b;
struct cmp
{
int x,y,z;
}a[N];
void phantich(int id,ll n)
{
int c=0;
while (n-MASK(c)>0)
{
b.push_back({a[id].x*MASK(c),a[id].y*MASK(c)});
n-=MASK(c);
c++;
}
if (n>0) b.push_back({a[id].x*n,a[id].y*n});
}
void nhap()
{
b.push_back({0,0});
cin>>n>>m;
for (int i=1;i<=m;i++)
cin>>a[i].x>>a[i].y>>a[i].z,
phantich(i,a[i].z);
///
for (int j=0;j<=n;j++)
{
for (int i=1;i<b.size();i++)
if (j-b[i].se>=0)
dp[i][j]=max(dp[i-1][j],dp[i-1][j-b[i].se]+b[i].fi);
else
dp[i][j]=dp[i-1][j];
}
cout<<dp[b.size()-1][n];
}
RVAN1102 {
ios_base::sync_with_stdio(false);
cin.tie(NULL);
#define task ""
#define task "a"
if(fopen(task".inp","r"))
{
freopen(task".inp","r",stdin);
freopen(task".out","w",stdout);
}
int t=1;
//cin>>t;
while (t--)
nhap();
}
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... |