private static int TopDown(Person[] people) { int[] counts = new int[people.Length]; int max = int.MinValue; for (int i = 0; i < counts.Length; i++) { max = Math.Max(max, CircusTower.GetCount(people, i, counts)); } return(max); }
private static int GetCount(Person[] people, int i, int[] counts) { if (counts[i] > 0) { return(counts[i]); } counts[i] = 1; for (int j = 0; j < people.Length; j++) { if (people[i].CanStandOn(people[j])) { counts[i] = Math.Max(counts[i], CircusTower.GetCount(people, j, counts) + 1); } } return(counts[i]); }