백준 온라인 저지/브루트 포스
15651번_N과 M (3)
King94
2019. 11. 14. 16:43
문제 출처 : https://www.acmicpc.net/problem/15651
<C++코드>
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
|
#include<iostream>
#include<vector>
#define MAX 9
using namespace std;
bool v[MAX];
int n,m;
vector<int> w;
void dfs(int cnt)
{
int find=true;
if(cnt==m)
{
for(int i=0;i<w.size();i++)
{
cout<<w[i]<<" ";
}
cout<<"\n";
return ;
}
for(int i=1;i<=n;i++)
{
v[i]=true;
w.push_back(i);
dfs(cnt+1);
v[i]=false;
w.pop_back();
}
}
int main(void)
{
ios::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
cin>>n>>m;
dfs(0);
return 0;
}
|
cs |