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
| import java.util.*
var n = 0 var m = 0 val arr = IntArray(10) val isUsed = BooleanArray(10)
fun main() = with(Scanner(System.`in`)) { n = nextInt() m = nextInt() backTrack(0) }
fun backTrack(k : Int) { if (k == m) { for (i in 0 until m) { print("${arr[i]} ") } println() return }
for (i in 1 .. n) { if (isUsed[i].not()) { arr[k] = i isUsed[i] = true backTrack(k+1) isUsed[i] = false } } }
|