private static List <HtWt> Initialize() { var item = new HtWt(65, 60); var items = new List <HtWt> { item }; item = new HtWt(70, 150); items.Add(item); item = new HtWt(56, 90); items.Add(item); item = new HtWt(75, 190); items.Add(item); item = new HtWt(60, 95); items.Add(item); item = new HtWt(68, 110); items.Add(item); item = new HtWt(35, 65); items.Add(item); item = new HtWt(40, 60); items.Add(item); item = new HtWt(45, 63); items.Add(item); return(items); }
private static void LongestIncreasingSubsequence(List <HtWt> array, List <HtWt>[] solutions, int currentIndex) { if (currentIndex >= array.Count || currentIndex < 0) { return; } HtWt currentElement = array[currentIndex]; // Find longest sequence that we can append current_element to List <HtWt> bestSequence = null; for (int i = 0; i < currentIndex; i++) { if (array[i].IsBefore(currentElement)) { // If current_element is bigger than list tail bestSequence = SeqWithMaxLength(bestSequence, solutions[i]); // Set best_sequence to our new max } } // Append current_element var newSolution = new List <HtWt>(); if (bestSequence != null) { newSolution.AddRange(bestSequence); } newSolution.Add(currentElement); // Add to list and recurse solutions[currentIndex] = newSolution; LongestIncreasingSubsequence(array, solutions, currentIndex + 1); }
public bool IsBefore(HtWt other) { return(_ht < other._ht && _wt < other._wt); }