N and M (3)
InterviewTime limit1sMemory limit512 MB
Print every length-M sequence from 1 to N in lexicographic order, allowing repeats.
- Level
Easy3 of 10
- Topics
- Backtracking, Recursion, Brute force, Implementation
- Solved
- No attempts yet
Problem
You are given two natural numbers and . Write a program that finds every sequence of length formed by choosing numbers from the natural numbers 1 to .
The same number can be chosen more than once.
Input
The first line contains two natural numbers and , separated by a space. ()
Output
Print one sequence that satisfies the condition per line. Separate the elements of each sequence with a space.
Do not print the same sequence twice. Print the sequences in increasing lexicographic order.