티스토리 뷰
https://www.acmicpc.net/problem/15654
const fs = require('fs');
const input = fs.readFileSync("./dev/stdin").toString().trim().split("\n").map(v=>v.split(' ').map(Number));
const [N,M] = input[0]
const nums = input[1].sort((a,b)=>a-b)
const answer = [];
class Node {
constructor(item) {
this.item = item;
this.next = null;
}
}
class Queue {
constructor() {
this.head = null;
this.tail = null;
this.length = 0;
}
push(item) {
const node = new Node(item)
if (this.head === null) {
this.head = node;
} else {
this.tail.next = node;
}
this.tail = node;
this.length += 1;
}
pop() {
const popItem = this.head.item;
this.head = this.head.next;
this.length -= 1;
return popItem;
}
}
let q = new Queue();
nums.forEach(v=>{
q.push([v])
})
while(q.length>0){
let arr = q.pop();
if(arr.length==M){
answer.push(arr.join(' '))
}else if(arr.length<M){
nums.forEach(v=>{
if(!arr.includes(v)){
q.push([...arr,v])
}
})
}
}
console.log(answer.join('\n'))
728x90
'자료구조 알고리즘 > 백준' 카테고리의 다른 글
Javascript) 최대공약수 최소공배수 (0) | 2021.12.30 |
---|---|
Node.js)백준 9613번: GCD 합 (0) | 2021.12.30 |
Node.js)백준 14500번: 테트로미노 (0) | 2021.12.30 |
Node.js)백준 1107번: 리모컨 (0) | 2021.12.30 |
Node.js)백준 6064번: 카잉 달력 (0) | 2021.12.29 |
공지사항
최근에 올라온 글
최근에 달린 댓글
- Total
- Today
- Yesterday
링크
TAG
- 투포인터
- 투포인터 연습
- 면접질문
- 다이나밍프로그래밍
- MySQL
- 개발자면접
- 면접비
- 서버개발
- create db
- BFS
- 은둔청년체험
- 롱베케이션
- 그래프
- create databases;
- 동적프로그래밍
- 다이나믹프로그래밍
- 최소공통조상
- DB 생성
- MOD
- 로드나인
- node.js
- 서버점검
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
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 |
글 보관함