| # | 제출 시각 | 아이디 | 문제 | 언어 | 결과 | 실행 시간 | 메모리 |
|---|---|---|---|---|---|---|---|
| 1179012 | genocidedheus | Knapsack (NOI18_knapsack) | C++20 | 1096 ms | 16244 KiB |
#include <bits/stdc++.h>
using namespace std;
int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
long long n,s,w,v,a,k,i,j;
vector<long long> weight;
vector<long long> value;
cin >> s >> n;
while(n--){
cin >> v >> w >> a;
k=1;
while(k<=a){
weight.push_back(w*k);
value.push_back(v*k);
a-=k;
k*=2;
}
if(a>0){
weight.push_back(w*a);
value.push_back(v*a);
}
}
vector<long long> DP(s+1,0);
for(i=0;i<weight.size();i++){
for(j=s;j>=weight[i];j--){
DP[j]=max(DP[j],DP[j-weight[i]]+value[i]);
}
}
cout << DP[s] << endl;
}| # | 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... | ||||
