이 제출은 이전 버전의 oj.uz에서 채점하였습니다. 현재는 제출 당시와는 다른 서버에서 채점을 하기 때문에, 다시 제출하면 결과가 달라질 수도 있습니다.
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <unordered_map>
#include <cmath>
#include <algorithm>
using namespace std;
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
using vi = vector<int>;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pdd = pair<double, double>;
const ll MOD = 1e9 + 7;
const int MAXN = 100000 + 7;
const int MAXM = 2010;
ll dp[MAXM], V[MAXN];
int W[MAXN], K[MAXN], cnt[MAXM];
int main() {
//freopen("feast.in", "r", stdin);
//freopen("feast.out", "w", stdout);
ios::sync_with_stdio(false);
int S, N;
cin >> S >> N;
for (int i = 0; i < N; i++) {
cin >> V[i] >> W[i] >> K[i];
}
fill(all(dp), -1);
dp[0] = 0;
for (int i = 0; i < N; i++) {
fill(all(cnt), K[i]);
for (int j = 0; j <= S; j++) {
if (dp[j] != -1) cnt[j] = 0;
}
for (int j = 0; j <= S; j++) {
if (j + W[i] <= S && dp[j] != -1 && cnt[j] < K[i]) {
dp[j + W[i]] = max(dp[j + W[i]], dp[j] + V[i]);
cnt[j + W[i]] = min(cnt[j] + 1, cnt[j + W[i]]);
}
}
}
ll res = 0;
for (int i = 0; i <= S; i++) {
res = max(res, dp[i]);
}
cout << res << endl;
}
# | 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... |