Knapsack problem with a constraint
Standard dynamic programming approaches are likely not going to work for this problem, because the extra &quot;this or that but not both&quot; constraints destroy the overlapping subproblems property. So let's break out the sledgehammer.
You can easily encode this as a 0-1 integer linear programming problem and use an off-the-shelf solver. For the given example (and some maximum weight limit $W$), a suitable 0-1 ILP problem is:
maximize $20A + 80B + 30C + 70D + 50E$
subject to
$A, B, C, D, E \in \{0, 1\}$
$10A + 50B + 20C + 30D + 50E \le W$
$A + B \le 1$
$C + E \le 1$
$A + D \le 1$
Although, it is not obvious to me that an integer linear programming solver will take full advantage of the structure of the problem. So perhaps a more specialized solution may perform better in practice.