Notice
Recent Posts
Recent Comments
Link
ยซ   2024/06   ยป
์ผ ์›” ํ™” ์ˆ˜ ๋ชฉ ๊ธˆ ํ† 
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
Archives
Today
Total
๊ด€๋ฆฌ ๋ฉ”๋‰ด

Lennon FE

[๋ฐฑ์ค€ 6603๋ฒˆ] ๋กœ๋˜ - ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ(nodejs) ๋ณธ๋ฌธ

๐Ÿ”ฅ Algorithm/Baekjoon

[๋ฐฑ์ค€ 6603๋ฒˆ] ๋กœ๋˜ - ์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ(nodejs)

Lennon 2022. 2. 6. 18:56
728x90
๋ฐ˜์‘ํ˜•

https://www.acmicpc.net/problem/6603

 

6603๋ฒˆ: ๋กœ๋˜

์ž…๋ ฅ์€ ์—ฌ๋Ÿฌ ๊ฐœ์˜ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ๋‹ค. ๊ฐ ํ…Œ์ŠคํŠธ ์ผ€์ด์Šค๋Š” ํ•œ ์ค„๋กœ ์ด๋ฃจ์–ด์ ธ ์žˆ๋‹ค. ์ฒซ ๋ฒˆ์งธ ์ˆ˜๋Š” k (6 < k < 13)์ด๊ณ , ๋‹ค์Œ k๊ฐœ ์ˆ˜๋Š” ์ง‘ํ•ฉ S์— ํฌํ•จ๋˜๋Š” ์ˆ˜์ด๋‹ค. S์˜ ์›์†Œ๋Š” ์˜ค๋ฆ„์ฐจ์ˆœ์œผ๋กœ

www.acmicpc.net

const fs = require('fs');
let input = fs
  .readFileSync('dev/stdin')
  .toString()
  .trim()
  .split('\n')
  .map((v) => v.split(' '));
input.pop();

const getCombinations = function (arr, selectNum) {
  const results = [];
  if (selectNum === 1) return arr.map((value) => [value]);

  arr.forEach((fixed, index) => {
    const rest = arr.slice(index + 1);
    const combinations = getCombinations(rest, selectNum - 1);
    const attached = combinations.map((combination) => [fixed, ...combination]);
    results.push(...attached);
  });

  return results;
};

input = input.map((v) => v.slice(1));

for (let i = 0; i < input.length; i++) {
  getCombinations(input[i], 6).forEach((v) => {
    console.log(v.join(' '));
  });
  console.log('');
}

์กฐํ•ฉ์„ ์‚ฌ์šฉํ•ด ์‰ฝ๊ฒŒ ํ’€ ์ˆ˜ ์žˆ๋‹ค.

728x90
๋ฐ˜์‘ํ˜•
Comments