Tree Problem Summary
Introduction
During the summer vacation, I systematically studied various operations on trees through Teacher Tuo's sharing and discovered many useful techniques, which I now summarize.
Teacher Tuo is amazing!
One
Problem Type: Batch processing queries of the form f(dep(lca(x,y))), where f(x) is a function of x.
Approach: First perform tree ...
Posted on Sat, 01 Aug 2026 16:21:20 +0000 by D_tunisia
C++ Algorithm Solutions for Competitive Programming Challenges
1. Gymnastic Team Formation
Given the small input constraints, a brute-force approach with backtracking and pruning is suitable. The solution uses depth-first search (DFS) to explore valid permutations while eliminating invalid paths early.
#include <iostream>
using namespace std;
int constraints[11] = {0};
bool used[11] = {false};
int v ...
Posted on Fri, 31 Jul 2026 16:00:17 +0000 by rlalande
SGU 132 - Another Chocolate Maniac
Given an $n \times m$ grid where each cell is either empty (.) or blocked (*), place the minimum number of $1 \times 2$ or $2 \times 1$ dominoes such that no two adjacent empty cells remain — i.e., it's impossible to place any additional domino.
Constraints: $1 \leq n \leq 70$, $1 \leq m \leq 7$.
Due to the small value of $m$, a dynamic program ...
Posted on Tue, 28 Jul 2026 16:01:51 +0000 by ultrus
Dynamic Programming and Game Theory Problems with Optimization Techniques
Problem 1: Optimized Dynamic Programming with Prefix Sums
This problem involves a basic dynamic programming approach where we process from the end to the beginning. The naive solution has a time complexity of O(n²), but we can optimize it using prefix sums and binary search.
We maintain a prefix sum array and for each position, use binary searc ...
Posted on Fri, 24 Jul 2026 16:47:03 +0000 by lorri
Dynamic Programming Solutions for Competitive Programming Problems
Potion-making Solution
This problem requires solving the equation i/(i+j) = k/100 to find the minimal total ingredients. The solution involves iterating through possiblle values of i and j.
#include <iostream>
#include <cmath>
using namespace std;
void solvePotion() {
int target_percentage;
cin >> target_percentage;
...
Posted on Mon, 20 Jul 2026 17:27:42 +0000 by pod2oo5
Longest Increasing Subsequence Algorithms
Longest Increasing Subsequence (LIS)
The Longest Increasing Subsequence problem involves findinng the maximum length of a strictly increasing subsequence from a given sequence of length n. The subsequence elements need not be contiguous in the original sequence.
Dynamic Programming Approach (O(n²))
State Representation
DP array: Stores the len ...
Posted on Sat, 18 Jul 2026 16:18:30 +0000 by Rebel7284
Sparse Table for Range Minimum/Maximum Query
Range Minimum/Maximum Query (RMQ)
The RMQ problem involves finding the minimum or maximum value within a specified range of an array of length n. Given multiple queries of the form RMQ(A, i, j), where i and j are indices in the array, the task is to return smallest or largest element between positions i and j.
Sparse Table Algorithm
The Sparse ...
Posted on Fri, 17 Jul 2026 17:14:57 +0000 by dharprog
Algorithmic Solutions: Interval Partitioning, Graph Matching, and Trie-Based Set Operations
Problem A: Large-Scale Simulation
A pure simulation problem centered on game theory mechanics. The implementation involves directly modeling the described rules and state transitions.
Problem B: Maximum Total Range for k-Partition
Define the weight of a subarray as its range (maximum element minus minimum element). For each k from 1 to n, compu ...
Posted on Thu, 16 Jul 2026 16:19:13 +0000 by killfall
Maximum Subtree Sum with Tree Dynamic Programming
We are given a tree of (n) nodes, each carrying an integer weight (which may be negative). The task is to select a connected subgraph that forms a subtree and maximise the sum of the node weights inside it. The problem appears with two common variants: one that allows an empty selection (answer at least 0) and one that requires at least one nod ...
Posted on Mon, 13 Jul 2026 16:31:14 +0000 by rodin
Optimizing Laser Path and Diagonal Grid Separation Problems
When solving this problem, precision errors in floating-point comparisons led to multiple failed submissions despite correct algorithmic logic. The challenge lies in grouping monsters by their directional vectors and efficiently computing the number of targets hit by a laser fired in a specific direction.
Monsters are represented as coordinate ...
Posted on Sat, 11 Jul 2026 17:06:05 +0000 by taha