-
15663) N과 M (9) c++백준코딩일기 2020. 12. 11. 09:18
코드 )
#include <iostream> #include <vector> #include <algorithm> using namespace std; int N, M; int arr[9]; vector<int> v; bool visited[9]; void func(int cnt) { if (cnt == M) { for (int i = 0; i < M; i++) cout << arr[i] << " "; cout << "\n"; } else { int last = 0; for (int i = 0; i < v.size(); i++) { if(!visited[i] && v[i] != last){ arr[cnt] = v[i]; last = arr[cnt]; visited[i] = 1; func(cnt+1); visited[i] = 0; } } } } int main(void) { ios::sync_with_stdio(0); cin.tie(0); cin >> N >> M; v.resize(N); for(int i=0; i<N; i++){ cin >> v[i]; } sort(v.begin(), v.end()); func(0); }
'백준코딩일기' 카테고리의 다른 글
15665) N과 M (11) c++ (0) 2020.12.11 15664) N과 M (10) c++ (0) 2020.12.11 15657) N과 M (8) c++ (0) 2020.12.11 15656) N과 M (7) c++ (0) 2020.12.11 15655) N과 M (6) c++ (0) 2020.12.11