当前位置: 首页> 健康> 知识 > 单仁牛商_网络推广一个月的收入_东莞推广平台有哪些_seo搜索推广费用多少

单仁牛商_网络推广一个月的收入_东莞推广平台有哪些_seo搜索推广费用多少

时间:2025/7/9 22:02:33来源:https://blog.csdn.net/2401_87338545/article/details/144220994 浏览次数:0次
单仁牛商_网络推广一个月的收入_东莞推广平台有哪些_seo搜索推广费用多少

题目一:排序数字

842. 排列数字 - AcWing题库

分析

考虑dfs,其实stl——next_permutation也可以

路径存储开一个数组,不能重复搜索,加一个标记数组

代码

#include<bits/stdc++.h>
using namespace std;int path[10];
int n;
bool vis[10];void dfs(int u) {if(u == n) { // 存完0-n-1,之后进入下一层输出层for(int i = 0; i < n; i ++) cout << path[i] << " ";puts("");return ;}for(int i = 1; i <= n; i ++) {if(!vis[i]) {vis[i] = true;path[u] = i;dfs(u+1);vis[i] = false;}}
}int main() {cin >> n;dfs(0);return 0;
}

题目二:n-皇后问题

843. n-皇后问题 - AcWing题库

 

分析

考虑dfs遍历每一列

用二维数组存图

用col标记一列,用dg 数组标记一条对角线,用udg标记一条反对角线

对角线表示:

截距 y = x +k,  k  = y-x.  即k = u-i (但是u-i可能为负数,数组越界 u-i + n)

反正对应一个空间标记一条线就行

y = -x + k,  k = y+x   即 k = u+i

代码

#include<bits/stdc++.h>
using namespace std;const int N = 11;
int n;
char a[N][N];
int col[N], dg[N], udg[N];void dfs(int u) {if(u == n) {for(int i = 0; i < n; i ++) {for(int j = 1; j <= n; j ++) {cout << a[i][j];}puts("");}puts("");return ;}for(int i = 1; i <= n; i ++) {if(!col[i] && !dg[i+u] && !udg[u-i+n]) {char t = a[u][i];a[u][i] = 'Q';col[i] = dg[i+u] = udg[u-i+n] = 1;dfs(u+1);col[i] = dg[i+u] = udg[u-i+n] = 0;a[u][i] = t;}}
}int main() {cin >> n;for(int i = 0; i < n; i ++) for(int j = 1; j <= n; j ++) a[i][j] = '.';dfs(0);return 0;
}

关键字:单仁牛商_网络推广一个月的收入_东莞推广平台有哪些_seo搜索推广费用多少

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: