์ž๋ฐ”์Šคํฌ๋ฆฝํŠธ ์•Œ๊ณ ๋ฆฌ์ฆ˜

[์ธํ”„๋Ÿฐ ์„น์…˜8] ์กฐํ•ฉ์˜ ๊ฒฝ์šฐ์ˆ˜ (Javascript)

์€์ง„ 2021. 6. 30. 11:44

์ธํ”„๋Ÿฐ

๐Ÿ‘ฉ๐Ÿปโ€๐Ÿ’ป๋ฌธ์ œ๋งํฌ

[์ธํ”„๋Ÿฐ ์„น์…˜8] ์กฐํ•ฉ์˜ ๊ฒฝ์šฐ์ˆ˜ (Javascript)
์œ ๋ฃŒ ๊ฐ•์˜์ธ ๊ด€๊ณ„๋กœ ๋ฌธ์ œ ์„ค๋ช…์€ ์ƒ๋žตํ•ฉ๋‹ˆ๋‹ค.


โœ๏ธIdea Sketch

2021-06-30

1. ์žฌ๊ท€๋ฅผ ์ด์šฉํ•ด ์กฐํ•ฉ์ˆ˜ ๊ตฌํ•˜๊ธฐ

2. DFS ์ข…๋ฃŒ์กฐ๊ฑด

  • ๋งค๊ฐœ๋ณ€์ˆ˜ = n, r
  • r ๋˜๋Š” n-r์ด 1์ธ ๊ฒฝ์šฐ, return n
  • 5C1 = 5C4 = 5!/4! = 5

3. DFS ๋‚ด๋ถ€๋กœ์ง

  • nCr = n-1Cr-1 + n-1Cr
  • DFS(n-1, r-1), DFS(n-1, r)


โœ๏ธ์†Œ์Šค์ฝ”๋“œ

2021-06-30

let c = 0;

function DFS(n, r) {
  if (r === 1 || n - r === 1) {
    c += n;
    return;
  }
  DFS(n - 1, r - 1);
  DFS(n - 1, r);
}

DFS(33, 19);
console.log(c);