제출 #703293

#제출 시각아이디문제언어결과실행 시간메모리
703293pahnKnapsack (NOI18_knapsack)C++14
37 / 100
1087 ms2260 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 s,n, a[mxN], b[mxN], c[mxN], dp[mxN][10005], m; void solve() { 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]; } int main(){ ios_base::sync_with_stdio(false); cin.tie(NULL); int t; // cin >> t; t = 1; while(t--) { solve(); } 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...