Okay, thank you for all the tips. I would have had pretty much the same idea that Winni had, that I would have needed to check the combinations of those people and their weight, and then just try to somehow extract the closest one to 500kg
"Please use this lift single or only with your relatives"
That is the way complicated math problems are solved today!
[…] The task requires, that I need to use the most weight in the lift that doesn't exceed 500kg. […]If you want to “cheat”, this kind of task is known as backpack problem (https://en.wikipedia.org/wiki/Backpack_problem) (except that your “backpack” is an elevator and all “items” have a constant value, since you merely want to maximize the number of people). By the mere length of the English Wikipedia page you can infer it’s not a simple task.
[…]That’s the brute-force approach. From your code I can see you already know enough to achieve that. You know how to access array components and how to use for-loops. The difficult thing is maybe to generate all possible passenger combinations, to construct a power set (https://en.wikipedia.org/wiki/Power_set).
You have to check
2+3+4+5 =
1+3+4+5 =
[…]
A big sign in the lift:
"Please use this lift single or only with your relatives"
... this kind of task is known as backpack problem (https://en.wikipedia.org/wiki/Backpack_problem) (except that your “backpack” is an elevator and all “items” have a constant value, since you merely want to maximize the number of people). By the mere length of the English Wikipedia page you can infer it’s not a simple task.This task would be a knapsack problem if initially it was required to select a group of passengers that maximizes the mass of the elevator with a limited load capacity.
This task would be a knapsack problem if initially it was required to select a group of passengers that maximizes the mass of the elevator with a limited load capacity. […]Huh, you’re right. Stycx’s second post describing the problem didn’t really point it out, but the opening post said there’s a line.