Ejemplo n.º 1
0
 private Node solve(int location, int flags, Node route, int cnt)
 {
     if (cnt == 6) {
         var lastNode = route.Next.Next.Next.Next.Next;
         Debug.Assert(lastNode != null);
         Debug.Assert(lastNode.Next == null);
         int head = lastNode.Value / 100;
         if (location == head)
             return route;
         else
             return null;
     }
     var links = table[location];
     if (links == null)
         return null;
     foreach (var link in links) {
         if ((flags & (1 << link.Kind)) != 0)
             continue;
         // visited
         var nextFlag = flags | (1 << link.Kind);
         var nextRoute = new Node(location * 100 + link.Next, route);
         var result = solve(link.Next, nextFlag, nextRoute, cnt + 1);
         if (result != null)
             return result;
     }
     return null;
 }
Ejemplo n.º 2
0
 private void Write(Node node)
 {
     int sum = 0;
     Node n = node;
     while (n != null) {
         sum += n.Value;
         n = n.Next;
     }
     Console.WriteLine(sum + " : " + node);
 }
Ejemplo n.º 3
0
 public Node(int value, Node next)
 {
     Debug.Assert(1000 < value && value <= 10000);
     this.Value = value;
     this.Next = next;
 }