Advertisement
tumaryui

Untitled

Jun 5th, 2020
132
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.88 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. #include <ctime>
  4. #include <algorithm>
  5.  
  6. using namespace std;
  7.  
  8. const int N = 3;
  9. const int n = 100 + N * 100; // количество предметов по варианту
  10. const int max_w = 500;
  11. int w[n];
  12. double c[n];
  13. double ww[n][max_w + 1];
  14.  
  15. int main() {
  16. srand(time(NULL));
  17. cout << fixed;
  18. for(int i = 0; i < n; i++) {
  19. c[i] = 0;
  20. w[i] = 0;
  21. for(int j = 0; j <= max_w; j++) {
  22. ww[i][j] = 0;
  23. }
  24. }
  25. for(int i = 0; i < n; i++) {
  26. w[i] = rand() % (10 + N) + 1;
  27. c[i] = 1 + (rand() % 100 + 1) * 0.01;
  28. }
  29. for(int i = 0;i < n;i++)
  30. {
  31. for(int j = 1;j <= max_w; j++)
  32. {
  33. if(j-w[i]>=0){
  34. ww[i][j]=max(ww[i-1][j],ww[i-1][j-w[i]]+c[i]);
  35. }
  36. else ww[i][j]=ww[i-1][j];
  37. }
  38. }
  39. cout << ww[n - 1][max_w];
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement