全排列dfs
2024-08-24 12:15:36
#include <iostream>
#include <vector>
using namespace std;
vector<int> ans;
const int maxn = 1e6 + 10;
int n,vis[maxn];
void dfs(int x)
{
if(x > n){
for(auto s : ans)
cout << s << " ";
cout << endl;
return;
}
for(int i = 1; i <= n;i++){
if(!vis[i]){
ans.push_back(i);
vis[i] = 1;
dfs(x + 1);
vis[i] = 0;
ans.pop_back();
}
}
}
int main()
{
cin >> n;
dfs(1);
return 0;
}
最新文章
- .NET单元测试的艺术-2.核心技术
- html-webpack-plugin插件的详细介绍和使用
- iOS10 UI教程视图的绘制与视图控制器和视图
- QT树莓派交叉编译环开发环境搭建(附多个exe工具下载链接)
- Ubuntu下远程访问MySQL数据库
- 解决由于VNC日志导致服务器磁盘100%
- Curl请求慢
- css-tips
- java第七周动手动脑
- (原)tensorflow使用eager在mnist上训练的简单例子
- MAC Gradle 下载的问题
- 牛刀小试MySQL--innodb_flush_log_at_trx_commit小结
- [PHP]PHP的session机制,配置与高级应用
- mysql 字符串数值计算 精度丢失
- Git项目的初始化
- 使用Chrome保存网页为mht文件
- 每日英语:China&#39;s Bigger Innovation Problem
- Swagger中显示注释
- 如何使用Total Recorder录制网上的音乐,如何下载只能试听的歌曲
- JS是面向过程、面向对象还是基于对象?面向对象的代码体现