제출 #866337

#제출 시각아이디문제언어결과실행 시간메모리
866337phuxtrohhgKnapsack (NOI18_knapsack)C++14
73 / 100
1086 ms9684 KiB
#include <bits/stdc++.h> #define ll long long #define pii pair<ll, ll> #define st first #define nd second #define all(x) (x).begin(), (x).end() #define mp(x) make_pair(x) #define file "test" using namespace std; const double PI = 2 * acos(0); const long long INF = 1e18; const long long N = 2e6 + 5; ll s, n, v[N], w[N], k[N]; ll dp[2][N]; int main() { ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0); // #ifndef ONLINE_JUDGE // freopen(file".inp","r",stdin); freopen(file".out","w",stdout); // #endif cin >> s >> n; for (int i = 1; i <= n; i++) cin >> v[i] >> w[i] >> k[i]; for (int i = 1; i <= n; i++) for (int j = 1; j <= s; j++) { int cur = i % 2; for (int sl = 1; w[i] * sl <= j && sl <= k[i]; sl++) dp[cur][j] = max(dp[cur][j], dp[!cur][j - w[i] * sl] + v[i] * sl); dp[cur][j] = max(dp[cur][j], dp[!cur][j]); } // for (int i = 1; i <=n; i++) // { // for (int j = 1; j <= s; j++) // cout << dp[i][j] <<' '; // cout << '\n'; // } cout << dp[n % 2][s]; }
#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...