| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1327890 | ghunglt | Knapsack (NOI18_knapsack) | C++20 | 1094 ms | 15852 KiB |
#include <algorithm>
#include <bits/stdc++.h>
#include <cctype>
using namespace std;
#define name "king2."
#define ll long long
#define vi vector<int>
const int N=1e7+5, mod=998244353, S=2005;
int n, s;
ll dp[S], w[N], v[N];
int main()
{
ios_base::sync_with_stdio(0);
cin.tie(0); cout.tie(0);
//freopen(name "in","r",stdin);
//freopen(name "out","w",stdout);
cin>>s>>n;
int cnt=0;
for (int i=1;i<=n;i++){
ll a,b,c;
cin>>a>>b>>c;
int k=1;
while (c>=k){
cnt++;
v[cnt]=a*k;
w[cnt]=b*k;
c-=k;
k*=2;
}
if (c>0){
cnt++;
v[cnt]=a*c;
w[cnt]=b*c;
}
}
for (int i=1;i<=cnt;i++){
for (int j=s;j>=w[i];j--) dp[j]=max(dp[j],dp[j-w[i]]+v[i]);
}
cout<<dp[s];
return 0;
}| # | 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... | ||||
