제출 #934115

#제출 시각아이디문제언어결과실행 시간메모리
934115KindaGoodGamesKnapsack (NOI18_knapsack)C++14
37 / 100
1058 ms476 KiB
#include <bits/stdc++.h> using namespace std; int const INF = numeric_limits<int>::max() / 2; #define ll long long string out = ""; bool hasCycles = false; #define pii pair<int,int> #define pll pair<ll,ll> #define tiii tuple<int,int,int> #define tiid tuple<double,int,int> int main() { cin.tie(0); ios_base::sync_with_stdio(false); int s, n; cin >> s >> n; vector<int> weight, value, amt; weight = value = amt = vector<int>(n); for (int i = 0; i < n; i++) { cin >> value[i] >> weight[i] >> amt[i]; } vector<ll> dp(s + 1); for (int j = 0; j < n; j++) { for (int i = s; i >= 0; i--) { for (int k = 0; k < amt[j]; k++) { if (weight[j] * (k + 1) > i) continue; dp[i] = max(dp[i], dp[i - ((k + 1) * weight[j])] + value[j] * (k + 1)); } } } ll ma = 0; for (auto d : dp) { ma = max(ma, d); } cout << ma; }
#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...