제출 #975002

#제출 시각아이디문제언어결과실행 시간메모리
975002vjudge1Knapsack (NOI18_knapsack)C++17
29 / 100
1 ms1368 KiB
#include <bits/stdc++.h> using namespace std; #define fast ios_base::sync_with_stdio(false); cin.tie(NULL); #define ll long long #define rep(i, n) for(int i = 0 ; i < n ; i++) #define all(a) a.begin(), a.end() // subsoal 1 & 2 int main() { fast int s, n; cin>>s>>n; int v[n+1], w[n+1], k[n+1]; rep(i, n){ cin>>v[i]>>w[i]>>k[i]; } if(n == 1){ int max = s/w[0]; if(max > k[0]){ cout<<v[0]*k[0]; return 0; } else{ cout<<v[0]*max; return 0; } } else{ int dp[n+1][s+1]; rep(i, s+1) dp[0][i] = 0; for(int i = 1 ; i<=n ; i++){ for(int j = 0 ; j<=s ; j++){ if(w[i-1] > j){ dp[i][j] = dp[i-1][j]; } else{ dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i-1]] + v[i-1]); } } } cout<<dp[n][s]; } return 0; }
#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...