제출 #756347

#제출 시각아이디문제언어결과실행 시간메모리
756347asdasdqwerKnapsack (NOI18_knapsack)C++14
컴파일 에러
0 ms0 KiB
#include <bits/stdc++.h> using namespace std; int main() { int s, n; cin >> s >> n; vector<int64_t> dp(s+1, 0); vector<pair<int64_t, int64_t>> items; for (int i = 0; i < n; i++) { int64_t v, w, k; cin >> v >> w >> k; k = min((s / k) + 1, k); for (int j = 0; j < k; j++) { items.push_back(make_pair(v, w)); } } sort(items.begin(), items.end()); int s = items.size(); for (int i = 0; i < s; i++) { for (int j = n; j > 0; j--) { if ((j - items[i].second > -1) && (dp[j - items[i].second] + items[i].first > dp[j])) { dp[j] = dp[j - items[i].second] + items[i].first; } } } cout << dp[n] << "\n"; }

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:23:9: error: redeclaration of 'int s'
   23 |     int s = items.size();
      |         ^
knapsack.cpp:5:9: note: 'int s' previously declared here
    5 |     int s, n;
      |         ^