https://www.acmicpc.net/problem/15651
15651번: N과 M (3)
한 줄에 하나씩 문제의 조건을 만족하는 수열을 출력한다. 중복되는 수열을 여러 번 출력하면 안되며, 각 수열은 공백으로 구분해서 출력해야 한다. 수열은 사전 순으로 증가하는 순서로 출력해
www.acmicpc.net
#include <stdio.h>
#define MAX 7
void print(int arr[], int m){
int i;
for(i=0;i<m;i++)
printf("%d ", arr[i]);
printf("\n");
}
void n_m(int arr[], int n, int m, int current){
int i;
if(current == m) {
print(arr,m);
return;
}
for(i=1;i<=n;i++){
arr[current] = i;
n_m(arr,n,m,current+1);
}
}
int main()
{
int n, m;
int arr[MAX];
scanf("%d %d", &n, &m);
n_m(arr, n, m, 0);
return 0;
}
지난 문제에서 중복을 검사하는 check() 함수를 제거한 뒤 실행시키기 정상동작을 확인할 수 있었다.
'프로그래밍 문제풀이' 카테고리의 다른 글
백준 2580번: 스도쿠 (0) | 2023.04.03 |
---|---|
백준 9663번: N-Queen (0) | 2023.04.02 |
백준 1562번: N과 M (4) (0) | 2023.04.02 |
백준 15650번: N과 M (2) (0) | 2023.04.01 |
백준 15649번: N과 M(1) (0) | 2023.03.31 |
댓글