N and M (6)
InterviewTime limit1sMemory limit512 MB
Given N distinct natural numbers and M, print every ascending M-element subsequence in lexicographic order without repeats.
- Level
Easy3 of 10
- Topics
- Backtracking, Sorting, Recursion, Brute force
- Solved
- No attempts yet
Problem
You are given natural numbers and a natural number . Write a program that finds every sequence of length that satisfies the conditions below. The natural numbers are all different.
- the sequence consists of numbers chosen from the given natural numbers
- the chosen sequence is in ascending order
Input
The first line contains and . ()
The second line contains numbers. Every number given in the input is a natural number less than or equal to 10,000.
Output
Print one sequence that satisfies the conditions per line. Do not print the same sequence twice, and separate the elements of each sequence with a space.
Print the sequences in increasing lexicographic order.