21.07.12 22:38 작성
·
236
0
분명히 같은 2차원 배열인것 같은데 왜 값이 다르게 나오는 것인가요??
<html>
<head>
<meta charset="UTF-8">
<title>출력결과</title>
</head>
<body>
<script>
function solution(n, r) {
let answer;
let dy2 = Array.from(Array(n + 1), () => Array(n + 1).fill(0));
let dy = Array(n + 1).fill(Array(n + 1).fill(0));
console.log(dy);
console.log(dy2);
function DFS(n, r) {
if(dy[n][r] > 0) return dy[n][r];
if(n === r || r ===0) return 1;
else return dy[n][r] = DFS(n - 1, r - 1) + DFS(n - 1, r);
}
answer = DFS(n, r);
return answer;
}
console.log(solution(5, 3));
</script>
</body>
</html>