There are marbles numbered from 1 to N. Of these, duplicates are allowed, and all methods of selecting M times and arranging them are printed out.
The first line is given the natural numbers N(3<=N<=10) and M(2<=M<=N).
3 2
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3
9
m
function solution(n, m) {
let answer = [];
for (let i = 1; i <= n; i++) {
for (let j = 1; j <= n; j++) {
console.log(i, j);
}
}
return answer;
}
m
function solution(n, m) {
let answer = [];
let tmp = Array.from({ length: m }, () => 0);
function DFS(L) {
if (L >= m) {
answer.push([...tmp]);
} else {
for (let i = 1; i <= n; i++) {
tmp[L] = i;
DFS(L + 1);
}
}
}
DFS(0);
return answer;
}