Hi! I encountered this problem recently: https://szkopul.edu.pl/problemset/problem/QT9Um-jnm6-sf8Gerxu1EbkL/site/?key=statement.
I have given it 2 days of thought and still haven't managed to come up with an idea to solve it. I thought to represent the items as a tree, with the dependent of item i being its father. Then we will perform dynamic programming on it. However, I am unable to figure out what to save in the states, and boolean arrays are simply too large to pass.