제출 #693343

#제출 시각아이디문제언어결과실행 시간메모리
693343hanluluKnapsack (NOI18_knapsack)C++14
12 / 100
1 ms340 KiB
#include <bits/stdc++.h> using namespace std; const int MOD = 1e9+7; int main() { ios::sync_with_stdio(false); cin.tie(0); cout.tie(0); //freopen("snakes.in","r",stdin); //freopen("snakes.out","w",stdout); long long s,n; cin >> s >> n; vector<long long> v(n+1),w(n+1),k(n+1); for (int i = 1; i<=n; i++) { cin >> v[i] >> w[i] >> k[i]; k[i] = min(k[i],s/w[i]); } vector< vector<long long> > dp(n+1,vector<long long>(s+1,0)); for (int j = 1; j <= s; j++) for (int i = 1; i <= n; i++) { for (int c = 1; c <= k[i] && c*w[i] <= j;c++) { //选c个物品i dp[i][j] = max(dp[i][j], dp[i-1][j- c*w[i]] + c*v[i]); } } cout << dp[n][s] << '\n'; 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...