Dynamic Programming Match Algorithm.