Fading Coder

One Final Commit for the Last Sprint

Dynamic Programming Solutions for Three Classic Problem Variants

This problem explores a classic dynamic programming approach with interesting variations. The fundamental question involves counting subsequences with certain properties. When the task is to count substrings, we use a well-established DP formulation: Define fi,j as the number of valid ways consider...

Dynamic Programming Essentials: Knapsack Variants and State Transitions

Understanding Problem Types in Dynamic Programming Dynamic programming problems often involve defining states and transitioning between them. Common types include: Knapsack Problems Linear DP Interval DP State Compression DP Tree DP Counting Problems Digit-based DP State Compression Memorized Search...

Algorithm Competition Problem Patterns and Templates

The following represents commonly encountered algorithmic challlenges during competitive programming practice, documented for reference purposes. Basic Algorithms Binary Search and Extremal Optimization Binary search can be applied beyond sorted arrays. When elements on one side of an array satisfy...

Summer 2024 Friendly Competition - Warmup Session 2

Summer 2024 Friendly Competition - Warmup Session 2A - Beautiful Reflections CodeForces - 1265E Problem Statement Creatnx has n (1 ≤ n ≤ 2×10^5) magical mirrors. Each day she asks one mirror: "Am I beautiful?" The i-th mirror tells Creatnx she is beautiful with probability p_i/100 (1 ≤ p_i...

Mastering Recursion Through Three Classic Problems

Tower of Hanoi: A Recursive Challenge The Tower of Hanoi is a classic puzzle involving three pegs and a number of disks of different sizes. The objective is to move the entire stack to another peg, following these rules: only one disk can be moved at a time, and a larger disk cannot be placed on top...

Using Union-Find with Path Compression and Dynamic Programming for Truth-Teller Identification

Problem Context An island has two types of inhabitants: truth-tellers, who always tell the truth, and liars, who always lie. Each inhabitent has a unique integer identifier. You are allowed n questions. Each question must be direcetd to one inhabitant, asking whether another inhabitant is a truth-te...

Essential LeetCode Problems for Algorithm Practice

Longest Increasing Subsequence To determine the length of the longest strictly increasing subsequence, dynamic programming is applied where dp[i] represents the length of the longest subsequence ending at index i. class Solution { public: int lengthOfLIS(vector<int>& sequence) { int size =...

Algorithmic Problem Solving: Contest Round Solutions

Problem A: Symmetric Pair Removal Given a binary string of length n, repeatedly remove a pair of characters from opposite ends if they differ (one is '0' and the other is '1'). Calculate the remaining length after no more valid pairs can be removed. A two-pointer technique efficiently solves this pr...

Competitive Programming Problem Set and Solutions

L1-1: Print Greeting Print a fixed greeting message. print("yuan shen, qi dong!") L1-2: Value Comparison Given a real number x, compare it to 1 and print the appropriate relational operator. #include <iostream> using namespace std; int main() { double val; cin >> val; if(val &l...

Solving Road Construction Problem Using Dynamic Programming Approach

Problem Analysis The road construction problem involves determining the minimum time required to complete paving operations across multiple segments. While algorithm tags suggest greedy approaches and binary indexed trees, a dynamic programming solution provides an elegant and efficeint implementati...