在接受采访时我问过你.你给我的矩阵填充了"1"和"0"."1"表示你可以使用单元格,"0"表示单元格被阻挡.你可以向4个方向移动左,右,上,下每次你向上或向下移动它都会花费你1美元.向左或向右移动不会增加成本.所以你必须编写一个代码来检查是否可以达到目的地索引( x,y)从(0,0)开始.如果是,则打印最低成本,否则打印"-1".
我无法计算成本.这是我的代码
public class Test {
/**
* @param args the command line arguments
*/
static int dest_x = 0;
static int dest_y = 0;
static int cost = 0;
static int m = 0;
static int n = 0;
public static void main(String[] args) {
// TODO code application logic here
Scanner in = new Scanner(System.in);
Test rat = new Test();
int maze[][] = {
{1, 1, 1, 1},
{1, 1, 1, 0},
{1, 1, 1, 1},
{0, …Run Code Online (Sandbox Code Playgroud)