Sei sulla pagina 1di 3

Instrucciones de tu profesor:

Pintar un mapa con la menor cantidad de colores posibles, la base del codigo ya se tiene
desarrollada (se trabajo en clase), entonces debes escribir las limitaciones para las
siguientes funciones:

class Main {

public static void main(String[] args) {

int[][] mapa

= new int[][]{{1, 1, 0, 1, 0},

{1, 1, 1, 1, 1},

{0, 1, 1, 0, 1},

{1, 1, 0, 1, 1},

{0, 1, 1, 1, 1}};

String[] colores = new String[]{"Azul", "Rojo", "Negro", "Blanco", "Verde"};

String[] sol = new String[]{"", "", "", "",""};

AsignarColoresBck(mapa, colores, sol);

private static boolean AsignarColoresBck(int[][] mapa, String[] colores, String[] res) {

//rechazar

if (!esBuenaOpcion(mapa, res)) {

return false;

//aceptar

if (esSolucion(res)) {

mostrar(res);

return true;

}
//movimiento

int c = 0;

for (int i = 0; i < res.length; i++) {

if (res[i].length() == 0) {

res[i] = colores[c];

AsignarColoresBck(mapa, colores, res);

res[i] = "";

c++;

c=c%colores.length;

return false;

private static boolean esBuenaOpcion(int[][] mapa, String[] res) {

// ESCRIBIR AQUI TU DEFINICION

private static boolean esSolucion(String[] res) {

// ESCRIBIR AQUI TU DEFINICION

private static void mostrar(String[] res) {

for (String re : res) {

System.out.print(" " + re);

}
System.out.println();

Potrebbero piacerti anche