-
15657) N과 M (8) c++백준코딩일기 2020. 12. 11. 09:00
코드 )
#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 { for (int i = num; i < N; i++) { arr[cnt] = v[i]; func(i, cnt+1); } } } 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); }
'백준코딩일기' 카테고리의 다른 글
15664) N과 M (10) c++ (0) 2020.12.11 15663) N과 M (9) c++ (0) 2020.12.11 15656) N과 M (7) c++ (0) 2020.12.11 15655) N과 M (6) c++ (0) 2020.12.11 15654) N과 M (5) c++ (0) 2020.12.11