7.9省赛加油

2086

AcWing2AK
Charlie0998
Exhausted
2010
WangJY

lsz_

1013308992

zeng9999jian
cdlyk

NO.1-Finn

https://www.acwing.com/file_system/file/content/whole/index/content/118289/?acwing_app_url=menu_friend_accept_invitation&record_uid=bdb374d8

？？？刚刚合星光璀璨打saber（好友），突然，系统显示我赢了！把我吓得半4qwq

# 这一题明显的全排列啊！

## dfs！dfs！dfs！重要的事情说三遍！

#include <bits/stdc++.h>
using namespace std;
int n, a[16];

bool f[16];

void dfs(int k) {
if (k > n) {
for (int i = 1; i <= n; i++)
cout << a[i] << " ";
cout << endl;
return ;
}//如果已经全部填好，就输出
for (int i = 1; i <= n; i++) {
if (f[i] == 0) {//如果数没有被填
f[i] = 1;//标记填入
a[k] = i;//填数
dfs(k + 1);//递归下一层
f[i] = 0;//反回状态
}
}
}

int main() {
cin >> n;//输入
dfs(1);//开始递归
return 0;
}


#include <bits/stdc++.h>
using namespace std;
int n, m, a[101];

bool f[16];

void dfs(int k) {
if (k > m) {
for (int i = 1; i <= m; i++)
cout << a[i] << " ";
cout << endl;
return ;
}
for (int i = a[k - 1] + 1; i <= n; i++) {
if (f[i] == 0) {
f[i] = 1;
a[k] = i;
dfs(k + 1);
f[i] = 0;
}
}
}

int main() {
cin >> n >> m;
dfs(1);
return 0;
}