Skip to content

Commit

Permalink
week13
Browse files Browse the repository at this point in the history
  • Loading branch information
sooyoung159 committed Mar 1, 2025
1 parent 1693c19 commit fabdfc5
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 50 deletions.
17 changes: 0 additions & 17 deletions src/sooyoung/jsAlgorithmStudy/week13/49-피로도.js
Original file line number Diff line number Diff line change
Expand Up @@ -25,22 +25,6 @@
// 첫 번째 입출력을 봅시다. 현재 피로도는 80 입니다. 만약 첫 번째 -* 두 번째 -* 세 번째 순서로 던
// 전을 탐험하면 다음과 같이 피로도의 총량을 계산할 수 있습니다.

const solution = (k, dungeons) => {
let maxDungeon = 0;
const backtrack = (sum, start) => {
if (sum > k) {
return;
}
maxDungeon = Math.max(maxDungeon, start);
for (let i = start; i < dungeons.length; i++) {
backtrack(sum + dungeons[i][0] - dungeons[i][1], i + 1);
}
};

backtrack(0, 0);
return maxDungeon;
};

function dfs(curk, cnt, dungeons, visited) {
let answerMax = cnt;
for (let i = 0; i < dungeons.length; i++) {
Expand All @@ -58,7 +42,6 @@ function dfs(curk, cnt, dungeons, visited) {

function solution(k, dungeons) {
const visited = Array(dungeons.length).fill(0);

const answerMax = dfs(k, 0, dungeons, visited);
return answerMax;
}
33 changes: 0 additions & 33 deletions src/sooyoung/jsAlgorithmStudy/week13/50-N퀸.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,6 @@
// 4
// result

const solution = n => {
let count = 0;
const cols = Array(n).fill(false);
const diags1 = Array(2 * n - 1).fill(false);
const diags2 = Array(2 * n - 1).fill(false);

const backtrack = row => {
if (row === n) {
count++;
return;
}

for (let col = 0; col < n; col++) {
const diag1 = row + col;
const diag2 = n - 1 + row - col;

if (cols[col] || diags1[diag1] || diags2[diag2]) {
continue;
}

cols[col] = diags1[diag1] = diags2[diag2] = true;
backtrack(row + 1);
cols[col] = diags1[diag1] = diags2[diag2] = false;
}
};

backtrack(0);
return count;
};

function search(n, y, width, diagonal1, diagonal2) {
let answer = 0;

Expand All @@ -46,11 +16,8 @@ function search(n, y, width, diagonal1, diagonal2) {
if (width[i] || diagonal1[i + y] || diagonal2[i - y + n]) {
continue;
}

width[i] = diagonal1[i + y] = diagonal2[i - y + n] = true;

answer += search(n, y + 1, width, diagonal1, diagonal2);

width[i] = diagonal1[i + y] = diagonal2[i - y + n] = false;
}
}
Expand Down

0 comments on commit fabdfc5

Please sign in to comment.