제출 #734886

#제출 시각아이디문제언어결과실행 시간메모리
734886vjudge1Knapsack (NOI18_knapsack)C++17
12 / 100
1 ms340 KiB
#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 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...