알고리즘
재귀로 짠 수열(?)
kyeongjun-dev
2020. 4. 25. 19:41
#include<bits/stdc++.h>
using namespace std;
int N, M;
int arr[10];
void dfs(int depth){
if(depth == M){
for(int i = 0; i<M; i++){
cout<< arr[i] << ' ';
}
cout<< '\n';
return;
}
//루프는 0~2까지
for(int i=0; i<N; i++){
arr[depth]=i+1;
dfs(depth+1);
}
}
int main(void){
cin>>N>>M;
dfs(0);
}
백트레킹을 이해하기 위해 재귀로 수열을 짜보았다.