private static void DFS(Problem node, int count, int minP, int maxP, int variety) { count++; if (minP > node.Pleasantness) { minP = node.Pleasantness; } if (maxP < node.Pleasantness) { maxP = node.Pleasantness; } if (maxP - minP >= variety) { if (minCount > count) { minCount = count; } } if (minCount < count) { count--; return; } foreach (var item in node.Children) { DFS(item, count, minP, maxP, variety); } count--; }
static void Main(string[] args) { int[] problems = Console.ReadLine().Split(new string[] { ", " }, StringSplitOptions.RemoveEmptyEntries).Select(int.Parse).ToArray(); int thresold = int.Parse(Console.ReadLine()); Queue<Problem> queue = new Queue<Problem>(); Problem currentProblem = new Problem(0, 1); queue.Enqueue(currentProblem); while (queue.Count > 0) { currentProblem = queue.Dequeue(); int cProblemNo = currentProblem.problemNo; if (cProblemNo + 1 >= problems.Length || Math.Abs(problems[cProblemNo] - problems[cProblemNo + 1]) >= thresold) { break; } if (cProblemNo + 2 >= problems.Length || Math.Abs(problems[cProblemNo] - problems[cProblemNo + 2]) >= thresold) { break; } queue.Enqueue(new Problem(cProblemNo + 1, currentProblem.depth + 1)); queue.Enqueue(new Problem(cProblemNo + 2, currentProblem.depth + 1)); } Console.WriteLine(currentProblem.depth); }