제출 #1079031

#제출 시각아이디문제언어결과실행 시간메모리
1079031vjudge1Knapsack (NOI18_knapsack)C++17
0 / 100
92 ms130564 KiB
#include <bits/stdc++.h> #include <map> using namespace std; #define fastIO ios_base::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr) #define all(x) x.begin(),x.end() #define take(x) for(int &el : x){ cin >> el;} typedef vector<int> vi; typedef vector<vi> vvi; typedef long long ll; const int MAX_N = 105; const int MAX_K = 15; const int MAX_S = 2005; int n, S, k, tot_size; ll v, w; ll memo[MAX_N * MAX_K][MAX_S]; vector<ll> V, W; ll dp(int id, ll remW) { if(remW == 0 || id == tot_size || W[id] > remW){return 0;} if(memo[id][remW] != -1){return memo[id][remW];} return memo[id][remW] = max(V[id] + dp(id + 1, remW - W[id]), dp(id + 1, remW)); } void solve(){ scanf("%d %d", &S, &n); memset(memo, -1, sizeof memo); V.clear(); W.clear(); for(int i = 0; i < n; i++) { scanf("%lld %lld %d", &v, &w, &k); for(int j = 0; j < k; j++) { V.push_back(v); W.push_back(w); } } tot_size = (int)V.size(); ll ans = dp(0, S); printf("%lld\n", ans); } int main(){ fastIO; int tc = 1; // scanf("%d", &tc); while (tc--) { solve(); } return 0; }

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

knapsack.cpp: In function 'void solve()':
knapsack.cpp:30:10: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   30 |     scanf("%d %d", &S, &n);
      |     ~~~~~^~~~~~~~~~~~~~~~~
knapsack.cpp:35:14: warning: ignoring return value of 'int scanf(const char*, ...)' declared with attribute 'warn_unused_result' [-Wunused-result]
   35 |         scanf("%lld %lld %d", &v, &w, &k);
      |         ~~~~~^~~~~~~~~~~~~~~~~~~~~~~~~~~~
#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...