Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <cmath>
- #include <iostream>
- #include <algorithm>
- #include <fstream>
- std::ifstream FileIn("Task.txt");
- double fullSearch(int i, double* arrayOfWeight, double* arrayOfCost, double curentWeight, int totalMaxWeight) {
- if (i < 0) {
- return 0;
- }
- double temp = 0;
- if (arrayOfWeight[i] + curentWeight <= totalMaxWeight) {
- temp = fullSearch(i - 1, arrayOfWeight, arrayOfCost, arrayOfWeight[i] + curentWeight, totalMaxWeight) + arrayOfCost[i];
- }
- return std::max(temp, fullSearch(i - 1, arrayOfWeight, arrayOfCost, curentWeight, totalMaxWeight));
- }
- int main() {
- int totalMaxWeight = 0, numberOfItem = 0;
- FileIn >> numberOfItem >> totalMaxWeight;
- double* arrayOfWeight = new double[numberOfItem];
- double* arrayOfCost = new double[numberOfItem];
- for (size_t i = 0; i < numberOfItem; ++i) {
- FileIn >> arrayOfWeight[i];
- }
- for (size_t i = 0; i < numberOfItem; ++i) {
- FileIn >> arrayOfCost[i];
- }
- double resOfFullSearch = fullSearch(numberOfItem - 1, arrayOfWeight, arrayOfCost, 0, totalMaxWeight);
- std::cout <<"Result of full search: "<< resOfFullSearch<<std::endl;
- delete[] arrayOfWeight;
- delete[] arrayOfCost;
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement