Problem Solving/BOJ
[BOJ] 15656 : N과 M (7)
shyram
2018. 12. 30. 00:50
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 | #include <bits/stdc++.h> using namespace std; int n, m; int arr[8]; int ans[8]; void solve(int depth) { if (depth == m) { for (int i = 0; i < m; i++) cout << ans[i] << ' '; cout << '\n'; return; } for (int i = 0; i < n; i++) { ans[depth] = arr[i]; solve(depth + 1); } } int main(void) { ios::sync_with_stdio(0); cin.tie(NULL); cin >> n >> m; for (int i = 0; i < n; i++) cin >> arr[i]; sort(arr, arr + n); solve(0); } | cs |