제출 #1192500

#제출 시각아이디문제언어결과실행 시간메모리
1192500dprtoKnapsack (NOI18_knapsack)C++20
0 / 100
0 ms328 KiB
#include <bits/stdc++.h> using namespace std; using ll = long long; #define x first #define y second #define MASK(i) (1 << (i)) #define BIT(x, i) (((x) >> (i)) & 1) #define f(i, l, r) for(int i = l; i <= r; ++i) const int mod = 1e9 + 7; const int ars = 2e3 + 5; const ll infll = 1e18; int s, n, v[ars], w[ars], k[ars], dp[ars]; signed main() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); cin >> s >> n; // Nhập thông tin các đồ vật f(i, 1, n) { cin >> v[i] >> w[i] >> k[i]; } // Khởi tạo mảng dp, giá trị mặc định là 0 f(i, 0, s) dp[i] = 0; // Duyệt qua từng đồ vật và cập nhật mảng dp f(i, 1, n) { // Xử lý đồ vật i (v[i], w[i], k[i]) f(j, s, w[i]) { f(c, 1, k[i]) { if (j >= c * w[i]) { dp[j] = max(dp[j], dp[j - c * w[i]] + c * v[i]); } } } } // In kết quả cuối cùng là giá trị tối đa có thể đạt được với trọng lượng tối đa s cout << dp[s] << "\n"; 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...