When using the simple dynamic programming approach (like above) you can only determine the length of the LCS with the last column, but not the actual sequence.
Here an example where it fails:
a a a a a c b b
c 0 0 0 0 0 1 1 1
b 0 0 0 0 0 1 2 2
b 0 0 0 0 0 1 2 3
a 1 1 1 1 1 1 2 3
a 1 2 2 2 2 2 2 3
a 1 2 3 3 3 3 3 3
a 1 2 3 4 4 4 4 4
Have a look at the Hirschberg algorithm. It is a divide and conquer adaptation of the Needleman-Wunsch algorithm and works in linear space.
For further reading: http://www.akira.ruc.dk/~keld/teaching/algoritmedesign_f03/Artikler/05/Hirschberg75.pdf