제출 #973459

#제출 시각아이디문제언어결과실행 시간메모리
973459vjudge1Knapsack (NOI18_knapsack)C++17
37 / 100
1030 ms10064 KiB
#include <bits/stdc++.h> #define ll long long using namespace std; const int INF = 1e9; int val[100001], weight[100001], stock[100001]; int dp[101][2001][11]; int main() { ios::sync_with_stdio(0); cin.tie(0); int s, n; cin >> s >> n; stock[0] = 0; for (int i = 1; i <= n; i++) { cin >> val[i] >> weight[i] >> stock[i]; } for (int i = 1; i <= n; i++) { for (int j = 0; j <= s; j++) { for (int k = 1; k <= stock[i]; k++) { dp[i][j][k] = dp[i - 1][j][stock[i - 1]]; if (j - weight[i] >= 0) { if (k > 1) { dp[i][j][k] = max(dp[i][j][k], dp[i][j - weight[i]][k - 1] + val[i]); } else { dp[i][j][k] = max(dp[i][j][k], dp[i - 1][j - weight[i]][stock[i - 1]] + val[i]); } } } } } cout << dp[n][s][stock[n]] << endl; 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...