题目大意:
串串字连环是利用一个5x5大小的英文字母格子进行的游戏。游戏规则是,连接上下左右/对角线方向上相邻的字母,组成一个单词。
const int dx[8] ={-1,-1,-1,1,1,1,0,0};
const int dy[8] ={-1,0,1,-1,0,1,-1,1};
bool hasword(int y,int x ,condt string&word){
//初始化部分1,如果在棋盘的外部,直接返回。
if(!inRange(y,x))return false;
// 初始化部分2,首字母不一致,也直接返回。
if(board[y][x] !=word[0])return false;
// 初始化部分3,单词长度为1了,说明这个路径的单词都对上了
if(word.size() == 1)return true;
//搜索周围8个格子
for(int direction = 0,direction<8;++direction){
int nextY = y+dy[direction] , nextX = x+dx[direction];
//只要有一个路径为true,就会返回真了
if(hasword(nextY,nextX,word.substr(1))
return true;
}
return false;
}