Friends, need help & suggestion in achieving the below

Above table clearly shows the Parent and Child combination but the catch is to consider own cost and child to show the rollup.. We have discovered a long method by introducing multiple line items (10 bare minimum; since the depth may be of 10 levels) but looking for more viable solution around the issue.
Help will be appreciated!