제출 #1092565

#제출 시각아이디문제언어결과실행 시간메모리
1092565AryanPadarthiKnapsack (NOI18_knapsack)C++11
컴파일 에러
0 ms0 KiB
// Source: https://usaco.guide/general/io #include <bits/stdc++.h> using namespace std; int main() { int w; int n; int mval=0; int bob; cin >> w >> n; vector<int> points(n); vector<int> weight(n); vector<int> count(n); vector<int> useful; for (int i = 0; i < n; i++){ cin >> points[i] >> weight[i] >> count[i]; } vector<int> dp(w+1,0); //dp[0]=1; for (int i = 0; i < n; i++){ for (int j = 0; j < count[i]; j++){ bob = dp[useful[k]]; for (int k = bob-1; k >-1 ; k--){ if (dp[useful[k]] > 0){ if (useful[k]+weight[i]<dp.size()){ dp[useful[k]+weight[i]] = max(dp[useful[k]+weight[i]],dp[useful[k]] + points[i]); useful.push_back(useful[k]+weight[i]); } } } if (j==0){ dp[weight[i]] = max(dp[weight[i]],points[i]); useful.push_back(weight[i]); } } } for (int i = 0; i < dp.size(); i++){ if (dp[i]>mval){ mval = dp[i]; } } cout << mval; }

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

knapsack.cpp: In function 'int main()':
knapsack.cpp:27:20: error: 'k' was not declared in this scope
   27 |    bob = dp[useful[k]];
      |                    ^
knapsack.cpp:31:29: warning: comparison of integer expressions of different signedness: '__gnu_cxx::__alloc_traits<std::allocator<int>, int>::value_type' {aka 'int'} and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   31 |      if (useful[k]+weight[i]<dp.size()){
knapsack.cpp:47:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   47 |  for (int i = 0; i < dp.size(); i++){
      |                  ~~^~~~~~~~~~~