이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <bits/stdc++.h>
#pragma GCC optimize ("-Ofast")
#pragma GCC optimize ("-Ofast")
#pragma GCC optimize(3)
#pragma GCC optimize("inline")
#pragma GCC optimize("-fgcse")
#pragma GCC target("avx","sse2")
#pragma GCC optimize("-fgcse-lm")
#pragma GCC optimize("-fipa-sra")
#pragma GCC optimize("-ftree-pre")
#pragma GCC optimize("-ftree-vrp")
#pragma GCC optimize("-fpeephole2")
#pragma GCC optimize("-ffast-math")
#pragma GCC optimize("-fsched-spec")
#pragma GCC optimize("unroll-loops")
using namespace std ;
using ll = long long ;
const int maxN = 5005, M = 1e5 + 5 ;
const ll mod = 1e9 + 7 ;
int S , N, V[M], W[M], K[M] ;
vector<map<int,ll>> dp(2001) ;
ll solve(int i, int j) {
if (i == N) return 0ll ;
if (dp[j].count(i)) return dp[j][i] ;
ll ret = 0 ;
for (ll c = 0 ; c <= K[i] && c * W[i] <= j ; c++) {
ret = max(ret, solve(i + 1, j - c * W[i]) + c * V[i]) ;
}
dp[j][i] = ret ;
return ret ;
}
int32_t main() {
ios::sync_with_stdio(false) ;
cin.tie(nullptr) ;
cin >> S >> N ;
for (int i = 0 ; i < N ; i++) {
cin >> V[i] >> W[i] >> K[i] ;
}
cout << solve(0, S) ;
return 0 ;
}
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |
# | Verdict | Execution time | Memory | Grader output |
---|
Fetching results... |