Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import java.awt.Point;
- import java.util.ArrayList;
- public class Main {
- public static Point[][][] restricted = new Point[][][]{{{new Point(0, 2), new Point(2, 0), new Point(2, 2)}, {new Point(1, 2)}, {new Point(0, 2), new Point(0, 0), new Point(2, 2)}},
- {{new Point(2, 1)}, {}, {new Point(0, 1)}},
- {{new Point(0, 0), new Point(2, 0), new Point(2, 2)}, {new Point(1, 0)}, {new Point(0, 2), new Point(2, 0), new Point(0, 0)}}};
- public static void main(String[] args) {
- System.out.println(step(null));
- }
- public static int step(ArrayList<Point> path) {
- int stepCount = 0;
- if (path == null) {
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < 3; j++) {
- ArrayList<Point> currPath = new ArrayList<Point>();
- currPath.add(new Point(i, j));
- stepCount += step(currPath);
- }
- }
- } else {
- if (path.size() >= 4) {
- stepCount++;
- }
- int id = path.size() - 1;
- for (int i = 0; i < 3; i++) {
- for (int j = 0; j < 3; j++) {
- // точка уже пройдена
- boolean can = true;
- for (int k = 0; k < path.size(); k++) {
- if (path.get(k).x == i && path.get(k).y == j) {
- can = false;
- }
- }
- if (!can) {
- continue;
- }
- // можно ли перейти
- Point[] currRestr = restricted[i][j];
- can = true;
- for (int k = 0; k < currRestr.length; k++) {
- // нельзя
- if (currRestr[k].equals(path.get(id))) {
- can = false;
- }
- }
- if (can) {
- ArrayList<Point> newPath = new ArrayList<Point>(path);
- newPath.add(new Point(i, j));
- stepCount += step(newPath);
- }
- }
- }
- }
- return stepCount;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement