Submission #839691

#TimeUsernameProblemLanguageResultExecution timeMemory
839691b14ck_5m0k3Knapsack (NOI18_knapsack)C++14
17 / 100
2 ms1876 KiB
/* author: b14ck_5m0k3 */ /* date: 30-08-2023 */ #include<bits/stdc++.h> #define int long long using namespace std; const int mod = 1000000007; signed main() { ios_base::sync_with_stdio(false); cin.tie(NULL); int S, N; cin >> S >> N; vector<int> V(N), W(N), K(N); for(int _ = 0; _ < N; _++) { cin >> V[_] >> W[_] >> K[_]; } vector<vector<int>> dp(N + 1, vector<int>(S + 1)); for(int i = 0; i < N; i++) { dp[i + 1] = dp[i]; for(int j = 0; j <= S; j++) { if(j + W[i] <= S) { dp[i + 1][j + W[i]] = max(dp[i + 1][j + W[i]], dp[i][j] + V[i]); } } } 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...