-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy path15657번.swift
34 lines (30 loc) · 893 Bytes
/
15657번.swift
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
28
29
30
31
32
33
34
// 출처 : 백준 N과 M (8)
// https://www.acmicpc.net/problem/15657
// 풀이 : hogumachu
import Foundation
func solution() {
let input = readLine()!.split(separator: " ").map{Int(String($0))!}
let n = input[0], m = input[1]
let numbers = readLine()!.split(separator: " ").map{Int(String($0))!}.sorted()
func visit(_ values: [Int], _ count: Int) -> Void {
if count == 1 {
var result = ""
for i in values {
result += "\(i) "
}
print(result)
} else {
for i in 0..<numbers.count {
if numbers[i] >= values.last! {
var nextValues = values
nextValues.append(numbers[i])
visit(nextValues, count-1)
}
}
}
}
for i in numbers {
visit([i],m)
}
}
solution()