제출 #1047877

#제출 시각아이디문제언어결과실행 시간메모리
1047877manhlinh1501Knapsack (NOI18_knapsack)C++17
17 / 100
2 ms2652 KiB
#include <bits/stdc++.h>
using namespace std;
const int MAXN = 1e5 + 5;

struct PRODUCT {
    int c, w, x;
    PRODUCT(int c = 0, int w = 0, int x = 0) : c(c), w(w), x(x) {}
};

int N, S;
PRODUCT a[MAXN];

namespace subtask {
    const int MAXN = 105;
    const int MAXV = 2e3 + 5;
    int dp[MAXN][MAXV];

    void solution() {
        for(int i = 1; i <= N; i++) {
            auto [c, w, x] = a[i];
            for(int j = 0; j <= S; j++) dp[i][j] = dp[i - 1][j];
            for(int z = 1; z <= x and w * x <= S; z++) {
                for(int j = S; j >= w * x; j--)
                    dp[i][j] = max(dp[i][j], dp[i - 1][j - w * z] + c * z);
            }
        }
        int ans = 0;
        for(int i = 1; i <= S; i++)
            ans = max(ans, dp[N][i]);
        cout << ans;
    }
}

signed main() {
#define TASK "code"

    if (fopen(TASK ".inp", "r")) {
        freopen(TASK ".inp", "r", stdin);
        freopen(TASK ".out", "w", stdout);
    }

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);

    cin >> S >> N;
    for(int i = 1; i <= N; i++) cin >> a[i].c >> a[i].w >> a[i].x;
    subtask::solution();
    return (0 ^ 0);
}

컴파일 시 표준 에러 (stderr) 메시지

knapsack.cpp: In function 'int main()':
knapsack.cpp:38:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   38 |         freopen(TASK ".inp", "r", stdin);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~
knapsack.cpp:39:16: warning: ignoring return value of 'FILE* freopen(const char*, const char*, FILE*)' declared with attribute 'warn_unused_result' [-Wunused-result]
   39 |         freopen(TASK ".out", "w", stdout);
      |         ~~~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~
#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...