Similar Items: Exact Dynamic Programming for Solow--Polasky Diversity Subset Selection on Lines and Staircases