제출 #1048755

#제출 시각아이디문제언어결과실행 시간메모리
1048755tamir1Knapsack (NOI18_knapsack)C++17
49 / 100
1067 ms2396 KiB
#include<bits/stdc++.h> #define ll long long using namespace std; ll n,S,i,j,l,res,dp[2005],s[100001],w[100001],k[100001]; int main(){ cin >> S >> n; for(i=1;i<=n;i++){ cin >> s[i] >> w[i] >> k[i]; } if(n==1){ cout << min(k[1],S/w[1])*s[1]; return 0; } for(i=1;i<=n;i++){ for(j=1;j<=k[i];j++){ for(l=S;l>=w[i];l--){ dp[l]=max(dp[l],dp[l-w[i]]+s[i]); } } } for(i=0;i<=S;i++) res=max(res,dp[i]); cout << res; }
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...
#Verdict Execution timeMemoryGrader output
Fetching results...