Solutions to Programming Contest Problems
Problem Solutions
Problem 1: Commute Calculation
#include <iostream>
using namespace std;
int main() {
int base, bonus1, bonus2;
cin >> base >> bonus1 >> bonus2;
cout << base + min(bonus1, bonus2) << endl;
return 0;
}
Problem 2: Adoration Count
#include <cstdio>
#include <algorithm& ...
Posted on Mon, 05 Oct 2026 16:36:31 +0000 by ca87
Grid Path Counting with and without Obstacles: Dynamic Programming Solutions
LeetCode 62. Unique Paths
A robot sits at the top‑left corner of an m × n grid (cell (0, 0)). It can only move down or right one step at a time. The goal is the bottom‑right corner (m-1, n-1). Compute the total number of distinct paths the robot can take.
Example 1
Input: m = 3, n = 7
Output: 28
Example 2
Input: m = 3, n = 2
Output: 3
Possible ...
Posted on Sun, 04 Oct 2026 16:17:47 +0000 by trillion
Dynamic Programming Fundamentals: Subsequence and Subarray Challenges
Problem 300: Longest Increasing Subsequence
Given an integer array, determine the length of the longest strictly increasing subsequence. A subsequence is derived by deleting zero or more elements without changing the order of remainign elements. Example: - Input: [10, 9, 2, 5, 3, 7, 101, 18] - Output: 4 - Explanation: The longest increasing sub ...
Posted on Sun, 04 Oct 2026 16:10:19 +0000 by Incredinot
Stock Trading Problems: Cooldown Period and Transaction Fee
Problem 309: Best Time to Buy and Sell Stock with Cooldown
Given an integer array prices where prices[i] represents the stock price on day i. Design an algorithm to calculate the maximum profit under the constraint that you cannot buy stock on the day after selling (one-day cooldown period).
Dynamic Programming Approach
The key to solving this ...
Posted on Sat, 03 Oct 2026 16:03:59 +0000 by kevintynfron
Dynamic Programming Solution for Edit Distance Problem
Problem Statement
Given two strings source and target, return the minimum number of opreations required to convert source in to target.
You can perform the following three operations on a string:
Insert a character
Delete a character
Replace a character
Example 1:
Input: source = "horse", target = "ros"
Output: 3
horse -& ...
Posted on Wed, 30 Sep 2026 16:04:27 +0000 by pedrokas
Competitive Programming Solutions: Graph Paths, DP, and Segment Trees
Problem A: Operations with Inversions
Greedy solution. Skipped for brevity.
Problem B: Optimal Shifts
Greedy solution. Skipped for brevity.
Problem C: Odd Process
Problem Statement: You have n numbers, each with a value a_i. You need to perform k rounds of operations where you can place a number into a bag (each number can only be placed once). ...
Posted on Tue, 29 Sep 2026 16:27:28 +0000 by Pilly
Implementing Merge Sort on Linked Lists and Solving the Climbing Stairs Problem
Merge Sort for Singly Linked Lists
When dealing with singly linked lists, Merge Sort is often the preferred sorting algorithm due to its O(n log n) time complexity and efficiency in sequential data structures. Unlike arrays, linked lists do not allow random access, which makes algorithms like QuickSort less efficient. The core logic relies on t ...
Posted on Thu, 24 Sep 2026 16:29:33 +0000 by ianhull
Algorithmic Solutions for Dynamic Programming and String Manipulation
Calculating Dice Roll CombinationsGiven d identical dice, each with f faces labeled from 1 to f, the objective is to determine the number of ways to achieve a specific sum target when rolling all dice. The result should be returned modulo 10^9 + 7.A recursive approach with memoization efficiently solves this by breaking the problem down into sm ...
Posted on Sun, 20 Sep 2026 16:15:08 +0000 by Floodboy
The Multiple Knapsack Problem
The Multiple Knapsack Problem
Given n types of items, where type i has c_i copies, value v_i, and weight w_i. We need to select items to maximize the total value in a knapsack with maximum capacity m.
Solution 1
One approach is to transform the multiple knapsack problem into a 0-1 knapsack problem. The naive method would be to split each item t ...
Posted on Thu, 17 Sep 2026 16:40:37 +0000 by jeffz2008
AGC022F Checkers: A Dynamic Programming Approach on Multi-way Trees
We examine the problem of merging \(n\) initial unit vectors \(\mathbf{e}_1,\ldots,\mathbf{e}_n\) via operations that combine two vectors \(\mathbf{u},\mathbf{v}\) into either \(2\mathbf{u} - \mathbf{v}\) or \(2\mathbf{v} - \mathbf{u}\), depending on which one "wins". Each final vector’s \(i\)-th component is of the form \((-1)^{c_i}2 ...
Posted on Tue, 15 Sep 2026 16:36:04 +0000 by cneale