제출 #703288

#제출 시각아이디문제언어결과실행 시간메모리
703288pahnKnapsack (NOI18_knapsack)C++14
37 / 100
1077 ms2264 KiB
#include <bits/stdc++.h> using namespace std; const int mxN = 1e3+5; const int M = 1e9+7; using vi = vector<int>; #define ll long long #define f first #define s second #define pii pair<int,int> #define pb push_back #define mp make_pair #define el '\n' ll n, m; ll a[mxN], b[mxN], c[mxN]; ll dp[mxN][10005]; int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); cin >> m >> n; for (int i = 1; i <= n; ++i) { cin >> b[i] >> a[i] >> c[i]; } for (int i = 1; i <= n; ++i) { for (int j = 1; j <= m; ++j) { for (int z = 0; z <= c[i]; ++z){ if (z*a[i] <= j) dp[i][j] = max(dp[i][j], dp[i-1][j - z*a[i]] + b[i]*z); } } } cout << dp[n][m]; }
#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...