-
15666) N과 M (12) c++백준코딩일기 2020. 12. 11. 10:01
코드 )
#include <iostream> #include <vector> #include <algorithm> using namespace std; int N, M; int arr[9]; vector<int> v; bool visited[9]; void func(int num, int cnt) { if (cnt == M) { for (int i = 0; i < M; i++) cout << arr[i] << " "; cout << "\n"; } else { int last = 0; for (int i = num; i < v.size(); i++) { if(v[i] != last){ arr[cnt] = v[i]; last = arr[cnt]; visited[i] = 1; func(i, 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, 0); }
'백준코딩일기' 카테고리의 다른 글
11057) 오르막 수 c++ (0) 2021.02.04 1152) 단어의 개수 c++ (0) 2021.01.13 15665) N과 M (11) c++ (0) 2020.12.11 15664) N과 M (10) c++ (0) 2020.12.11 15663) N과 M (9) c++ (0) 2020.12.11