제출 #1092564

#제출 시각아이디문제언어결과실행 시간메모리
1092564AryanPadarthiKnapsack (NOI18_knapsack)C++11
0 / 100
308 ms262144 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++){ for (int k = useful.size()-1; k >-1 ; k--){ bob = dp[useful[k]]; if (bob > 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:30: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]
   30 |      if (useful[k]+weight[i]<dp.size()){
knapsack.cpp:46:20: warning: comparison of integer expressions of different signedness: 'int' and 'std::vector<int>::size_type' {aka 'long unsigned int'} [-Wsign-compare]
   46 |  for (int i = 0; i < dp.size(); i++){
      |                  ~~^~~~~~~~~~~
#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...