|
This reminds me of a program I once wrote in a programming contest that had the requirement of finding the fewest number of coins with which to make change. The problem was that you couldn't just use a greedy algorithm, as there were occasions that using the largest coins first actually forced you into a situation where you'd end up using more coins than necessary.
As I've understood your program, you find the largest possible palindrome, and assume it's part of the solution. It's a good guess, but unfortunantly wrong. I think that's why your getting 85 instead of 84; the way you're doing it is fundamentally flawed.
This might be an NP-Complete problem, I'm willing to bet some of the older coders could tell us. If this is a programming assignment, it's a tough one.
|