제출 #698022

#제출 시각아이디문제언어결과실행 시간메모리
698022xr_cKnapsack (NOI18_knapsack)C++17
0 / 100
103 ms262144 KiB
#include <cstring> #include <iostream> using namespace std; int s, n, w[100001], v[100001], k[100001]; int dp[100001][2001]; int main() { // freopen("debug.cerr", "w", stderr); memset(dp, 0, sizeof(dp)); cin >> s >> n; for (int i = 1; i <= n; i++) { cin >> v[i] >> w[i] >> k[i]; } // for (int i = 1; i <= n; i++) // cerr << k[i] << ' '; // cerr << endl; for (int i = 1; i <= n; i++) { for (int j = 1; j <= s; j++) { for (int l = 1; l <= k[i] && l * w[i] <= j; l++) { dp[i][j] = max(dp[i][j], dp[i - 1][j - l * w[i]] + l * v[i]); } dp[i][j] = max(dp[i][j], dp[i - 1][j]); } } // for (int i = 1; i <= n; i++) { // for (int j = 1; j <= s; j++) { // cerr << dp[i][j] << '\t'; // } // cerr << endl; // } 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...