Here's a possible solution also from personal experience: I went to high school in Texas and about 70% of the top students went to University of Texas at Austin because a) very good school (top 10 in CS) b) at least at the time, you got in automatically by being in the top 8% of your class, which isn't that hard in huge Texas schools c) not cheap but not $40k a year.
Most parents realized this was a likely outcome for the kids early on (or pretty much expected them to go there) and started to save up money since their child was born. The result was the most unstressful college application process I've seen!
Of course, not everyone lives in a state where the flagship public college is a top 10 in CS and many other majors, nor can everyone save up 18 years before the kid goes to college, but some can make it happen.