Hello, jarny!

I have a rather primitive approach.

Maybe someone has a more elegant solution.

Each car of a five-car train must be painted a solid color.

The only color choices are red, blue, and yellow.

If each of these colors must be used for at least one car,

in how many ways can this train be painted?

The color distribution could be 3-1-1. .(Three of one color, one each of the others.)

. . There are ways this could be done: RRRBY, RBBBY, RBYYY.

Once the colors are chosen, the trains can be painted in: . ways.

Hence, there are: ways to have 3-1-1.

The color distribution could be 2-2-1. .(Two each of two colors, one of the third.)

. . There are ways this could be done: RRBBY, RRBYY, RBBYY.

Once the colors are chosen, the trains can be painted in: . ways.

Hence, there are: ways to have 2-2-1.

Therefore, there are: . ways to paint the trains.