[C언어] 백준 15652 : N과 M (4)

mainsain·2022년 3월 21일
0

백준

목록 보기
28/64


같다. https://velog.io/@seochan99/15652-N-%EA%B3%BC-M-4 이사람 코드다.
유형을 익히자.

#include <stdio.h>

int n, m;
int result[1000];

void DFS(int depth, int cut)
{
    int i;

    if (depth == m)
    {
        for (int i = 0; i < m; i++)
            printf("%d ", result[i]);
        printf("\n");
    }
    else
    {
        for (i = 1; i <= n; i++)
        {
            if (cut <= i)
            {
                result[depth] = i;
                DFS(depth + 1, i);
            }
        }
    }
}

int main(void)
{
    scanf("%d %d", &n, &m);
    DFS(0, 0);
    return 0;
}

16560에서 cut을 살리고 범위를 i이하로 수정해주면 된다

profile
새로운 자극을 주세요.

0개의 댓글