Thread: From C to Java
View Single Post
Old 07-13-2004, 07:14 AM   #10 (permalink)
Belisarius
Java fanboy
 
Belisarius's Avatar
 
Join Date: Aug 2003
Posts: 1,161
Belisarius is on a distinguished road
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.
__________________
GitS
Belisarius is offline   Reply With Quote