Skip to content

Ферзи N на N#3

Open
stuffacc wants to merge 3 commits intomainfrom
t4
Open

Ферзи N на N#3
stuffacc wants to merge 3 commits intomainfrom
t4

Conversation

@stuffacc
Copy link
Owner

No description provided.

Copy link

@Godrik0 Godrik0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

По заданию просили 3 варианта решения, вижу только одно.
$O(n^{n+4})$ это прям очень плохо, эффективное решение предполагает $O(n!)$.

@stuffacc stuffacc requested a review from Godrik0 December 16, 2025 10:09
Copy link

@Godrik0 Godrik0 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Стоило разделить решения на три отдельных файлика

Comment on lines +108 to +130
def solve_n_queens_util(board, col):
# Если все ферзи расставлены
if col >= len(board):
return 1

count = 0
for row in range(len(board)):
if is_valid(board, row, col):
# Расставление ферзя
board[row][col] = 1

# В следующий столбец
count += solve_n_queens_util(board, col + 1)
# Удаление ферзя
board[row][col] = 0

return count

def solve_n_queens(n):
board = [[0 for _ in range(n)] for _ in range(n)]
return solve_n_queens_util(board, 0)

print(solve_n_queens(n))
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Но ведь это тоже рекурсивное решение, а в complexity.md названо переборным

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants