How can I solve this Tower Building problem?

Hello,
I am aware this might not fit C++ specifically, but I have nowhere else to ask this and I couldn't find it online in this format.

Given n cubes, each of a color and size, what is the tallest tower I can build with them such that no cube is on top of a smaller cube and that no 2 cubes of the same color touch.
Some cubes can be of the same size.

What is an optimal algorithm for this?
Thanks
Topic archived. No new replies allowed.