Computing Minimum Knight Moves on a Chessboard Using BFS and DFS
Given an n × m chessboard (with 1 < n, m ≤ 400) and the starting position of a knight, determine the minimum number of moves required for the knight to reach every other square. If a square is unreachable, output -1.
Input Format
A single line containing four integers: n, m, start_x, and start_y.
Output Format
Print an n × m matrix. Each val ...
Posted on Tue, 09 Jun 2026 17:50:23 +0000 by fourteen00
Solving AtCoder Beginner Contest 367 Problems with C++
A - Shout Everyday
This problem involves checking if a specific hour falls within a given time range spanning across midnight. We handle the wrap-around by adjusting the end time.
#include <cstdio>
int main() {
int target, start, end;
scanf("%d %d %d", &target, &start, &end);
if (end <= start) en ...
Posted on Tue, 09 Jun 2026 16:32:03 +0000 by $var
Solution: COCI 2015-2016 #6 Problem SAN
Problem Analysis: Digit DP
Before explaining the correct solution, let's first discuss the partial score approach.
For 50% of the data, where (1 \le L, R \le 10^6), a brute force simulation might be feasible. However, since we don't know the exact positions where each number appears, directly simulating with a 2D array is likely to cause memory ...
Posted on Thu, 28 May 2026 19:36:55 +0000 by Fawkman
Minimum Button Presses for a Strange Elevator
A building has an unusual elevator system. Each floor i (where 1 ≤ i ≤ N) has a fixed value K[i], which determines how many floors the elevator moves when the "up" or "down" button is pressed. The elveator can only move up by K[i] floors or down by K[i] floors from floor i. If the target floor would be below 1 or above N, th ...
Posted on Mon, 18 May 2026 01:53:57 +0000 by bobdabuilder
Backtracking the N-Queens Puzzle with Early Output
Given an n × n chessboard, place n queens so that no two attack each other. A valid placement guarantees exactly one queen per row and per column, and at most one queen on every diagonal (both positive and negative slopes). The task is to enumerate every valid configuration, print the first three in lexicographical order, and finally output the ...
Posted on Sat, 16 May 2026 16:22:06 +0000 by mtucker6784
Combination Sum II - Handling Duplicate Elements in Backtracking
Given an array of integers candidates and a target value target, find all unique combinations in candidates where the numbers sum to target.
Key constraints:
Each number can only be used once in each combination.
All numbers (including the target) are positive integers.
The result set must not contain duplicate combinations.
Examples
Example ...
Posted on Sun, 10 May 2026 11:27:21 +0000 by smilley654
Backtracking with Element Tracking for Deduplication
Problem 491: Non-decreasing Subsequences
Given an integer array nums, return all the different non-decreasing subsequences that have atleast two elements. The answer can be in any order. When two integers are equal, this counts as a valid increasing sequecne.
Example 1:
Input: nums = [4,6,7,7]
Output: [[4,6],[4,6,7],[4,6,7,7],[4,7],[4,7,7],[6,7 ...
Posted on Fri, 08 May 2026 23:26:45 +0000 by mcccy005
Foundations of Search: Classic Problems and Algorithmic Insights
A: Chessboard Rook Placement
Given an (n \times n) board where certain positions marked # allow placement, determine the number of ways to place (k) identical, non-attacking rooks. Constraints: (k \leq n \leq 8).
Since each row can hold at most one rook, a depth-first search over rows is feasible. The state space is bounded by ((n+1)^n), at mos ...
Posted on Thu, 07 May 2026 01:45:42 +0000 by benzrf