ext_2403 ([identity profile] mskala.livejournal.com) wrote in [personal profile] ciphergoth 2005-11-06 05:53 pm (UTC)

At a glance this looks like a job for dynamic programming, but I think it can actually be done in linear time if you do this:

Compute, for the first k tiles, the optimal solution that DOES and the optimal solution that DOES NOT have a match in the last position.

From those two solutions it's easy to compute a similar pair of solutions for the first k+1 tiles.

Repeat until you've done all the tiles, then keep whichever of the two solutions you have, is better.

The big advantage: you can prove the above correct without needing to prove that a (potentially long and complicated) list of pattern-matching templates is correct and complete.

Post a comment in response:

(will be screened)
(will be screened if not validated)
If you don't have an account you can create one now.
HTML doesn't work in the subject.
More info about formatting

If you are unable to use this captcha for any reason, please contact us by email at support@dreamwidth.org