Originally Posted by

**sam8868tw**
How many possible painting solutions do I have?

What is a painting solution? Is the idea that one can of paint is precisely enough to paint one wall and you want to know all possible ways the walls can be colored?

Using your example, since one can is needed for each of the 5 walls the first step must be to find out in how many different ways one can pick out 5 cans. A set of 5 cans can have 0 to 5 cans of yellow, 0 to 3 cans of red and 0 to 2 cans of blue. Then to find out how a certain set of 5 cans can be used to paint the 5 walls you generate all permutations of that set.

There may be smarter ways but the simplest is to use three nested loops like this,

Code:

for (int yellow=0; yellow<=5; ++yellow) {
for (int red=0; red<=3; ++red) {
for (int blue=0; blue<=2; ++blue) {
if (yellow+red+blue == 5) {
// 1. All different color combinations of 5 cans are available here one by one.
// 2. All permutations of each such color combination then give all ways
// the 5 walls can be painted using that particular color combination.
}
}
}
}

Fortunately there's a permutation function in the C++ standard library,

http://www.cplusplus.com/reference/a...t_permutation/