This is basically what my colleague wrote above, but I've had students who needed more structure, so perhaps this will help someone.
First, make the problem into a table. You know that you need some of the 20% solution, some of the 50% solution, and some total amount. You also know that you will be working with both liters and percentages.
| 20% | 50% | Total (The header for your table.)
liters: x +y = 12
percentages: 20x +50y =40(12) (This is the line where lots of students seem to have trouble. "Okay, I see where you're getting the 20, 50, and 40, but how'd you know to put the 12 there?" I hear. My response: "Remember the x and y are amounts in liters of the different solutions, so we can read the percentage line as: 20 percent of how ever many liters of this solution plus 50 percent of how ever many liters of that solution have to equal 12 liters of 40 percent solution. I'm just writing all of the percentages in the front of each term." At which point I usually have to remind them to write on their papers what I just said, so it still makes sense when they're doing homework. Granted, there are other ways of making sense of that line, but that seems to work for many students.)
Okay, so the table was basically a way for us to make sense of the problem and find two equations that we can use together (with elimination, substitution, matrices, or even graphing will work on this one) to solve for x and y. I'll use elimination today. Here are our two equations:
x + y = 12
20x +50y =40(12) We can choose to "eliminate" either variable, but I'll pick on the x today. As long as you multiply (or divide) each term of an equation by the same value, it's still mathematically sound.
So, take 20x +50y =40(12) and divide each term by 20 (because we're picking on x and want to take all of the x's stuff).
20x/20 +50y/20 =40(12)/20
x + 2.5y =24 Now subtract each term from the other equation...
-x - 1 y = -12
1.5y=12 (No more exes; we've got one less problem without it...) So, solve it.
y = 8 So, we'll need 8 liters of the 50% solution, but x + y = 12, so if y=8, then x=4.
So, we'll need 4 liters of the 20% solution.