Advertisement
tumaryui

Untitled

Jun 4th, 2020
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.60 KB | None | 0 0
  1. #include <iostream>
  2. #include <vector>
  3. using namespace std;
  4.  
  5. int main() {
  6. int n = 1200; // количество предметов по варианту
  7. int max_w = 500;
  8.  
  9. vector<int> w(n);
  10. vector<double> c(n);
  11. vector<vector<double> > ws(n, vector<double> (max_w + 1, 0));
  12. for(int i = 0; i < n; i++) {
  13. w[i] = rand();
  14. c[i] = rand() / RAND_MAX + 1;
  15. }
  16. for(int i = 0; i < n; i++) {
  17. for(int j = 0; j <= max_w; j++) {
  18. if(j < w[i]) {
  19. ws[i][j] = ws[i - 1][j];
  20. } else {
  21. ws[i][j] = max(ws[i][j], ws[i - 1][j - w[i]] + c[i]);
  22. }
  23. }
  24. }
  25.  
  26. cout << ws[n][max_w];
  27. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement