rendered paste body// Jim Herreroimport java.io.*;import java.util.*;public class cookiemonster{ public static void main() throws IOException { Scanner sc = new Scanner(new File("cookies.dat")); int[][] map = new int[12][12]; int x = 0, y = 0; Stack<Integer> endvalues = new Stack<Integer>(); while(sc.hasNextInt()) { map[y][x] = sc.nextInt(); x++; if(x == 12) y++; x %= 12; } findPaths(map, endvalues, 0, 0, 0); int bestvalue = 0; while(!endvalues.empty()) if(endvalues.peek() > bestvalue) bestvalue = endvalues.pop(); else endvalues.pop(); System.out.println("Best Result = " + bestvalue + " cookies"); } public static void findPaths(int[][] map, Stack<Integer> endvalues, int total, int x, int y) { total += map[y][x]; if(x < 11 && map[y][x+1] != -1) findPaths(map, endvalues, total, x+1, y); if(y < 11 && map[y+1][x] != -1) findPaths(map, endvalues, total, x, y+1); if(x == 11 && y == 11) endvalues.push(total); }}