fork download
  1. #include <iostream>
  2. #include <vector>
  3. #include <unordered_map>
  4. #include <string>
  5.  
  6. using namespace std;
  7.  
  8. vector<pair<int, int>> v;
  9.  
  10. int knapsack(int n, int w) {
  11. if (n == 0 || w == 0) {
  12. return 0;
  13. }
  14.  
  15. int weight = v[n - 1].first;
  16. int value = v[n - 1].second;
  17.  
  18. if (weight > w) {
  19. return knapsack(n - 1, w);
  20. }
  21. return max(knapsack(n-1,w),knapsack(n-1,w - weight)+value);
  22. }
  23.  
  24. int main(){
  25. ios::sync_with_stdio(false);
  26. cin.tie(nullptr);
  27.  
  28. int n, w;
  29. cin >> n >> w;
  30.  
  31. for (int i = 0; i < n; i++) {
  32. int w, v;
  33. }
  34.  
  35.  
  36.  
  37. }
  38.  
Success #stdin #stdout 0s 5324KB
stdin
Standard input is empty
stdout
Standard output is empty