Left/right hand separation based on dynamic programming