
Jesús Rojas
Zeta
Verificación en dos pasos activada
Buenas noches quisiera ver si me pudieran ayudar con una tarea de programacion en java soy nuevo en eso y quisiera que me ayuden me piden que tenga una matriz de 3x3 llenado aleatoriamente de 1 y 0 ! y me pidieron que haga con backtracking que desde un punto de inicio! busquemos en toda la matriz los 1 y lo convirtamos en 0 ! y que me diga cuantos movimientos hizo para que cambie todos los 1 a 0 ! y que me vaya imprimiendo cada vez que hago un movimiento!
estuve generando la matriz aleatoriamente! pero me falta el metodo backtracking o algun otro metodo que recorra toda la matriz y vaya buscando los 1 y los convierta en ceros y que vaya sumando la cantidad de movimientos que hizo para que todo los 1 se conviertan a 0
aqui les dejo el codigo que estuve haciendo
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package agente;
import java.util.Random;
/**
*
* @author AndyVladimir
*/
public class Agente {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int x[][] = new int[3][3];
Random r = new Random();
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
x[j]=r.nextInt(2);
}
}
imprimir(x);
}
public static void imprimir(int[][] x) {
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
System.out.print(x[j] + " ");
}
System.out.println();
}
}
}
estuve generando la matriz aleatoriamente! pero me falta el metodo backtracking o algun otro metodo que recorra toda la matriz y vaya buscando los 1 y los convierta en ceros y que vaya sumando la cantidad de movimientos que hizo para que todo los 1 se conviertan a 0
aqui les dejo el codigo que estuve haciendo
/*
* To change this license header, choose License Headers in Project Properties.
* To change this template file, choose Tools | Templates
* and open the template in the editor.
*/
package agente;
import java.util.Random;
/**
*
* @author AndyVladimir
*/
public class Agente {
/**
* @param args the command line arguments
*/
public static void main(String[] args) {
// TODO code application logic here
int x[][] = new int[3][3];
Random r = new Random();
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
x[j]=r.nextInt(2);
}
}
imprimir(x);
}
public static void imprimir(int[][] x) {
for(int i=0;i<3;i++){
for(int j=0;j<3;j++){
System.out.print(x[j] + " ");
}
System.out.println();
}
}
}