제출 #1086122

#제출 시각아이디문제언어결과실행 시간메모리
1086122lukasuliashviliKnapsack (NOI18_knapsack)C++17
73 / 100
96 ms2412 KiB
#include <bits/stdc++.h> using namespace std; const int N=10005; long long v[N],w[N],dp[N][N],k[N]; int main() { int s,n; cin>>s>>n; for(int i=1; i<=n; i++){ cin>>v[i]>>w[i]>>k[i]; /// v[i]_value w[i]_weight } for(int i=0; i<=n; i++){/// i_ramdeni itemi shedis j_ra masa eteva for(int j=0; j<=s; j++){ if(i==0 or j==0 ){ dp[i][j]=0; continue; } dp[i][j]=dp[i-1][j]; /// tu nivti ar aviget; for(int count=1; count<=k[i]; count++){ if(j-count*w[i]<0) break; dp[i][j]=max(dp[i][j],dp[i-1][j-w[i]*count]+v[i]*count); } } } cout<<dp[n][s]<<endl; }
#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...