Tiered scene labeling with dynamic programming