Dynamic programming/ LIS / LDS