迷宫算法可能很难,有一种偷懒的办法:暴力枚举一个随机迷宫,然后判断是否有解,也可以完成这个程序,下面我给大家一段参考代码(用到了记忆化搜索)
#include <iostream>
#include <cstdlib>
#include <ctime>
#include <windows.h>
#include <conio.h>
#include <random>//记得在连接器里添加-std=c++11
using namespace std;
long long path[101][101];
int grey[101][101];
char grey2[101][101];
long long calculate(int x, int y) {
if (path[x][y] == -1) {
long long result = 0;
if ((x == 0) && (y == 0)) {
result = 1;
}
if ((x > 0) && !grey[x - 1][y]) {
result += calculate(x - 1, y);
}
if ((y > 0) && !grey[x][y - 1]) {
result += calculate(x, y - 1);
}
path[x][y] = result;
}
return path[x][y];
}
void gotoxy(int x, int y) {
COORD pos = {x, y};
HANDLE hOut = GetStdHandle(STD_OUTPUT_HANDLE);
SetConsoleCursorPosition(hOut, pos);
}
int main() {
int x, y,