Dynamic programming/LIS/LDS