본문 바로가기

Algorithm

(C++) - 백준(BOJ) 15651번 : N과 M (3)

반응형
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
#include <iostream>
using namespace std;
int n, m;
int a[8];
int ck[8];
void DFS(int t)
{
    if (t == m)
    {
        for (int i = 0; i < m; i++)
        {
            cout << a[i] << ' ';
        }
        cout << '\n';
        return;
    }
    for (int i = 1; i <= n; i++)
    {
        a[t] = i;
        DFS(t+1);
    }
}
 
int main() {
    cin >> n >> m;
    DFS(0);
}
cs