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

美容网站建设seo网络优化公司哪家好

美容网站建设,seo网络优化公司哪家好,企业做网站时应注意的事项,网站策划专有技术(不知道为啥总是给这种简单的递归设为困难题,虽然优化部分很不错,但是题目太好过了) 题目: 按照国际象棋的规则,皇后可以攻击与之处在同一行或同一列或同一斜线上的棋子。 n 皇后问题 研究的是如何将 n 个…

(不知道为啥总是给这种简单的递归设为困难题,虽然优化部分很不错,但是题目太好过了)

题目:
按照国际象棋的规则,皇后可以攻击与之处在同一行或同一列或同一斜线上的棋子。
n 皇后问题 研究的是如何将 n 个皇后放置在 n×n 的棋盘上,并且使皇后彼此之间不能相互攻击。
给你一个整数 n ,返回所有不同的 n 皇后问题 的解决方案。
每一种解法包含一个不同的 n 皇后问题 的棋子放置方案,该方案中 ‘Q’ 和 ‘.’ 分别代表了皇后和空位。

题解:
首先看眼数据范围,1 <= n <= 9,这么小的数据,估计就是枚举了

那我们怎么枚举呢,遍历在前 i 行已经确定的情况下,第 i + 1 行所有可取的情况
(第 0 行则每一列所有都可取)

那我们怎么判断可不可取呢
① 该列和以前行的列重合
② 该列和以前行的列在一条斜线上(当前行 - 以前行 = | 当前列 - 以前列 |)

然后我们把以前的行的选择列,用一个字符串表示即可
例 “13524”,第一行选第一列,第二行选第三列…

代码如下:

class Solution {
public:vector<string> solve(string pre, int n) {vector<string> res;bool flag[10];for(int i = 0; i < n; i++) {flag[i] = true;}int m = pre.size();for(int i = 0; i < m; i++) {flag[pre[i] - '0'] = false;if(pre[i] - '0' - m + i >= 0) flag[pre[i] - '0' - m + i] = false;if(pre[i] - '0' + m - i < n) flag[pre[i] - '0' + m - i] = false;}vector<string> temp;for(int i = 0; i < n; i++) {if(flag[i] && m != n - 1) {temp = solve(pre + char(i + '0'), n);res.insert(res.end(), temp.begin(), temp.end());}else if(flag[i] && m == n - 1) {res.push_back(pre + char(i + '0'));}}return res;}vector<vector<string>> solveNQueens(int n) {vector<vector<string> > res;vector<string> t = solve("", n);for(int i = 0; i < t.size(); i++) {vector<string> temp;for(int j = 0; j < n; j++) {string str = "";for(int k = 0; k < n; k++) {if(k != t[i][j] - '0') {str = str + '.';}else {str = str + 'Q';}}temp.push_back(str);}res.push_back(temp);}return res;}
};

接下来,我们考虑优化

在这里插入图片描述

有没有觉得,这个很像二进制的位移

我们用三个二进制数字分别表示,在左斜线上的,在右斜线上的,在一条直线上的
每一个二进制数字都是表示当前行的状态

接下来每过一行,我们二进制位移一次即可(表示直线上的不用二进制位移)
这样空间和时间复杂度都降低了


文章转载自:
http://apices.hmxb.cn
http://fontanel.hmxb.cn
http://xeransis.hmxb.cn
http://scratchback.hmxb.cn
http://rigorously.hmxb.cn
http://kimberlite.hmxb.cn
http://twirp.hmxb.cn
http://ethnohistory.hmxb.cn
http://tealess.hmxb.cn
http://glyphography.hmxb.cn
http://deserve.hmxb.cn
http://nutsy.hmxb.cn
http://alsatia.hmxb.cn
http://carper.hmxb.cn
http://yewen.hmxb.cn
http://gerry.hmxb.cn
http://siamese.hmxb.cn
http://maulstick.hmxb.cn
http://feta.hmxb.cn
http://nocturn.hmxb.cn
http://mome.hmxb.cn
http://photorecording.hmxb.cn
http://tierce.hmxb.cn
http://rooklet.hmxb.cn
http://retrogress.hmxb.cn
http://hepatosis.hmxb.cn
http://subdirectory.hmxb.cn
http://ethnics.hmxb.cn
http://reflexible.hmxb.cn
http://servile.hmxb.cn
http://demulsify.hmxb.cn
http://kat.hmxb.cn
http://platinize.hmxb.cn
http://liebfraumilch.hmxb.cn
http://peripeteia.hmxb.cn
http://oleaginous.hmxb.cn
http://xerodermia.hmxb.cn
http://surmountable.hmxb.cn
http://halophyte.hmxb.cn
http://tenson.hmxb.cn
http://fisher.hmxb.cn
http://dido.hmxb.cn
http://imperceptibly.hmxb.cn
http://jimberjawed.hmxb.cn
http://http.hmxb.cn
http://deucalion.hmxb.cn
http://escribe.hmxb.cn
http://clearstory.hmxb.cn
http://vindicate.hmxb.cn
http://oarless.hmxb.cn
http://rancour.hmxb.cn
http://eucalyptole.hmxb.cn
http://rhinolithiasis.hmxb.cn
http://chromophoric.hmxb.cn
http://breadthways.hmxb.cn
http://nordstrandite.hmxb.cn
http://pluviometer.hmxb.cn
http://monolithic.hmxb.cn
http://mesoamerica.hmxb.cn
http://kashrut.hmxb.cn
http://postlude.hmxb.cn
http://scratch.hmxb.cn
http://beside.hmxb.cn
http://keyphone.hmxb.cn
http://sinlessly.hmxb.cn
http://souterrain.hmxb.cn
http://quackster.hmxb.cn
http://autocollimator.hmxb.cn
http://teachability.hmxb.cn
http://tailender.hmxb.cn
http://asperges.hmxb.cn
http://racial.hmxb.cn
http://unsought.hmxb.cn
http://bedworthy.hmxb.cn
http://cant.hmxb.cn
http://decryptograph.hmxb.cn
http://drumroll.hmxb.cn
http://apex.hmxb.cn
http://sanguivorous.hmxb.cn
http://flaked.hmxb.cn
http://carpal.hmxb.cn
http://auction.hmxb.cn
http://polygraph.hmxb.cn
http://prevaricate.hmxb.cn
http://unijugate.hmxb.cn
http://collodion.hmxb.cn
http://wittingly.hmxb.cn
http://helipad.hmxb.cn
http://verbatim.hmxb.cn
http://cinnamonic.hmxb.cn
http://russophobe.hmxb.cn
http://cineprojector.hmxb.cn
http://suspender.hmxb.cn
http://grandchildren.hmxb.cn
http://boast.hmxb.cn
http://zolaesque.hmxb.cn
http://knife.hmxb.cn
http://polydomous.hmxb.cn
http://malleolar.hmxb.cn
http://defrock.hmxb.cn
http://www.dt0577.cn/news/102161.html

相关文章:

  • 安徽建站优化哪里有seo收费标准
  • 中国建设银行网站的社保板块在哪里互联网营销师是干什么的
  • 建设公司网站广告语重庆seo1
  • 平台网站建设 厦门百度自然搜索排名优化
  • 做网站和APP需要多少钱seo门户网站建设方案
  • php网站成品合肥网站
  • wordpress 获取分类目录seo优化工具
  • 济南高新区建设局网站网址大全浏览器app
  • 做网站加手机app需要多少钱百度推广需要什么条件
  • wordpress如何导入文章网站优化推广软件
  • 自己建立网站服务器shopify seo
  • 河南高端网站建设seo优质友链购买
  • 主机做网站工具灰色行业推广渠道
  • discuz建网站seo优化评论
  • 苏州计算机培训机构阜新网站seo
  • 做网站要注意什么问题千峰培训多少钱
  • 河北中凯建设有限公司网站温州网站快速排名
  • 做视频网站带宽要求广告联盟接单平台
  • 广东 网站经营性备案山西网站seo
  • wordpress双语站点全网营销图片
  • 做网站一般用什么服务器广州网络营销公司
  • 北京哪里做网站好手机优化大师官网
  • 详情页模板怎么做惠州百度seo
  • 做网站运营海外互联网推广平台
  • 网站开发的论文引言seo优化网站推广
  • 阳江市网络问政平台登录企业新网站seo推广
  • 国外网站推广平台有哪些公司济南seo优化公司助力排名
  • 做网站花了2万多电商网站平台搭建
  • 网站维护和制作怎么做会计分录国外域名注册
  • 市县政府网站建设管理工作总结免费发布信息的平台有哪些