Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <vector>
- #include <ctime>
- #include <algorithm>
- using namespace std;
- const int N = 3;
- const int n = 100 + N * 100; // количество предметов по варианту
- const int max_w = 500;
- int w[n];
- double c[n];
- double ww[n][max_w + 1];
- int main() {
- srand(time(NULL));
- cout << fixed;
- for(int i = 0; i < n; i++) {
- c[i] = 0;
- w[i] = 0;
- for(int j = 0; j <= max_w; j++) {
- ww[i][j] = 0;
- }
- }
- for(int i = 0; i < n; i++) {
- w[i] = rand() % (10 + N) + 1;
- c[i] = 1 + (rand() % 100 + 1) * 0.01;
- }
- for(int i = 0;i < n;i++)
- {
- for(int j = 1;j <= max_w; j++)
- {
- if(j-w[i]>=0){
- ww[i][j]=max(ww[i-1][j],ww[i-1][j-w[i]]+c[i]);
- }
- else ww[i][j]=ww[i-1][j];
- }
- }
- cout << ww[n - 1][max_w];
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement