Untitled

 avatar
unknown
plain_text
2 years ago
1.1 kB
4
Indexable
package day11_1306;

import java.util.Scanner;



public class painting {
	
	static int n, value;
	static int[] d = {0, 1, 2, 3};
	static int[][] map;
	static int[] color;
	
	private static boolean check(int v, int i){
		for(int j = 0; j < n; j++){
			if(map[v][j] == 1 && color[j] == i)
				return false;
		}
		return true;
	}
	
	private static void Try(int v){
		if(v == n){
			value++;
			return;
		}
		for(int i = 0; i < 4; i++){
			if(check(v, i)){
				color[v] = i;
				Try(v + 1);
				color[v] = -1;
			}
		}
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int testcase = sc.nextInt();
		for(int tc = 1; tc <= testcase; tc++){
			n = sc.nextInt();
			
			map = new int[n][n];
			color = new int[n];
			for(int i = 0; i < n; i++){
				color[i] = -1;
			}
			
			for(int i = 0; i < n; i++){
				for(int j = 0; j < n; j++){
					map[i][j] = sc.nextInt();
				}
			}
			value = 0;
			
			Try(0);
			
			System.out.println("Case #" + tc);
			System.out.println(value);
		}
	}
}
Editor is loading...