当前位置: 首页 > news >正文

建设网站的技术方案是啥萧山市seo关键词排名

建设网站的技术方案是啥,萧山市seo关键词排名,抖音采用了哪些网络营销方式,网站建设图总结Problem: 面试题 08.12. 八皇后 文章目录 题目描述思路解题方法复杂度Code 题目描述 思路 八皇后问题的性质可以利用回溯来解决,将大问题具体分解成如下待解决问题: 1.以棋盘的每一行为回溯的决策阶段,判断当前棋盘位置能否放置棋子 2.如何判…

Problem: 面试题 08.12. 八皇后

文章目录

  • 题目描述
  • 思路
  • 解题方法
  • 复杂度
  • Code

题目描述

在这里插入图片描述

思路

八皇后问题的性质可以利用回溯来解决,将大问题具体分解成如下待解决问题:

1.以棋盘的每一行为回溯的决策阶段,判断当前棋盘位置能否放置棋子
2.如何判断当前棋盘位置是否可以放置棋子

解题方法

1.回溯函数:

1.1定义二维结果集result,char类型二维数组(作为棋盘)并初始化
1.2当决策阶段row等于n时,将当前的决策路径添加到result中(注意决策阶段应该等于n时才说明将棋盘判断完了,因为当决策阶段等于n时说明0 - n-1 已经判断处理完)
1.3由于在每一个决策阶段我们需要对棋盘的每一列棋格判断(穷举),所以以每一列为循环判断(调用判断当前位置是否可以添加棋子的函数),若可以则先将棋盘当前位置添上棋子,再回溯判断当前行的下一行,判断完当前行后还需恢复当前棋盘位置的状态

2.判断当前位置是否可以添加棋子函数

2.1依次利用循环判断当前位置的列,右上角,左上角是否存在棋子,存在则不可在当前位置添加棋子

复杂度

时间复杂度:

O ( n ! ) O(n!) O(n)

空间复杂度:

O ( n ) O(n) O(n)

Code

class Solution {//Two-dimensional result setprivate List<List<String>> result = new ArrayList<>();/*** Get the solution to the Eight Queens problem** @param n The size of board* @return List<List < String>>*/public List<List<String>> solveNQueens(int n) {char[][] board = new char[n][n];for (int i = 0; i < n; ++i) {for (int j = 0; j < n; ++j) {board[i][j] = '.';}}backtrack(0, board, n);return result;}/*** Find the solution of the eight queens problem by backtracking** @param board Board* @param row   The row of board(The decision stage of backtracking)* @param n     The size of board*/private void backtrack(int row, char[][] board, int n) {//End condition:A feasible solution is foundif (row == n) {List<String> snapshot = new ArrayList<>();for (int i = 0; i < n; ++i) {snapshot.add(new String(board[i]));}result.add(snapshot);return;}//Each has n ways to placefor (int col = 0; col < n; ++col) {if (isOk(board, n, row, col)) {//optional list//The chess board places pieces in row rows and col columnsboard[row][col] = 'Q';//Investigate the next rowbacktrack(row + 1, board, n);//Recover the selectionboard[row][col] = '.';}}}/*** Determines whether the current column can place chess pieces** @param board The board* @param n     The row number and column number of board* @param row   The row number of board* @param col   The column number of board* @return boolean*/private boolean isOk(char[][] board, int n, int row, int col) {//Check whether columns conflictfor (int i = 0; i < n; ++i) {if (board[i][col] == 'Q') {return false;}}//Check whether top right corner conflictint i = row - 1;int j = col + 1;while (i >= 0 && j < n) {if (board[i][j] == 'Q') {return false;}i--;j++;}//Check whether top left corner conflicti = row - 1;j = col - 1;while (i >= 0 && j >= 0) {if (board[i][j] == 'Q') {return false;}i--;j--;}return true;}
}
http://www.zhongyajixie.com/news/31368.html

相关文章:

  • 风险地区查询最新长沙seo排名外包
  • 建设一个网站方象科技服务案例
  • 宁波妇科中医哪个好有利于seo优化的是
  • 爱站工具包官网下载吉林关键词优化的方法
  • 宁波做外贸网站推广沈阳seo网站推广
  • 江苏省中医院网站建设深圳seo优化
  • 嘉兴五县两区网站建设关键词优化骗局
  • app试玩网站制作友情链接交换方式有哪些
  • 地方网站模板西安外包网络推广
  • 应用商店软件大全seo产品是什么意思
  • 做企业的网站都要准备什么手续怎么把网站排名到百度前三名
  • 选择建设网站公司要注意什么站长统计app软件下载官网安卓
  • 滕建建设集团网站cpm广告联盟平台
  • 求职招聘网站开发百度seo词条优化
  • 做网站的时候遇到的问题北京网络推广公司
  • 用python做的大型网站软件培训
  • 网站续费申请合肥网络推广培训学校
  • wordpress修改网站标题seo文章生成器
  • 做网站需要哪些东西网站关键词优化排名
  • 苏州网站制作哪家靠谱亚马逊seo是什么意思
  • 做婚纱网站是怎么确认主题福建百度seo排名点击软件
  • access做网站数据库seo网站关键词快速排名
  • 济南专门做网站的公司国际热点事件
  • 上海家装十强企业seo是网络优化吗
  • 做积分商城网站线上销售的方法和技巧
  • 网站服务器的选择seo代码优化包括哪些
  • 做海报的专业网站百度指数名词解释
  • 秦皇岛网站开发公司东莞网站推广企业
  • 关于政府网站建设的情况说明优化seo哪家好
  • 中国农业建设信息网站搜索引擎营销的优缺点