everyone! While I was solving the problems from cses.fi I came across the one that I totally couldn't understand. I searched the Internet and found the solution with DP along subsets, but still wasn't able to realize why it works. The problem is below with its solution... https://cses.fi/problemset/task/1653 https://cses.fi/book/book.pdf (page 103 - 104)
In short, the author offers to count for each subset to values: the minimum number of rides requiered ('rides(S)') and for that number of rider the minimum weight of the last group of people ('last(S)'). And if we consider some set S then we need to take some its element p, extract it from S, recount required values rides(S\p) and last(S\p) trying to add the element p to the smallest group with weight last(S\p) if it's possible and to create a new group for p otherwise. Then we need to repeat that algorithm for all possible p in the set S and take the minimum possible pair {rides(S\p);last(S\p)}.
Please, tell me why do we get the requiered values for S during the algorithm I described. I don't understand why it goes through all the possible options, why it's exhaustive.
I tried to prove its accuracy, but I'm not so good at maths.