Problem Overview Luogu P1509 "Finding a Girlfriend" presents a multi-constraint 0/1 knapsack problem. Given n items, each with three attributes rmb_i (money), rp_i (reputation), and time_i (time spent), the goal is to maximize the number of selected items such that the sum of rmb_i does no...
Simulation Contest 2 Solutions Current Progress: Linear DP, Knapsack Problems, Intervals Challenging Problems 1038 [NOIP2008] Paper Passing Tags High-Dimensional DP Approach The challenge lies in ensuring that the path from (1,1) to (n,m) and back from (n,m) to (1,1) do not overlap. It can be treate...
Problem A: Minimum Function Summation Given the function f(x) = min_{i∈ℕ⁺}, compute the sum Σ_{i=1}^{n} f(i) modulo 10^9+7 across multiple test cases. Constraints: n ≤ 10^16, T ≤ 10^4. Solution Approach: Analyze the frequency of each value in the sequence f(i). For a particular value x, we need to c...
Energy beads on a circcular necklace each have a head and tail marker, both positive integers. Adjacent beads satisfy that the tail of one equals the head of the next. Merging two adjacent beads with head a, tail b and head b, tail c releases energy a * b * c, producing a new bead with head a and ta...
Given a integer n, detremine the minimum number of perfect squares that sum to n. A perfect square is a integer that equals another integer multiplied by itself. For example: 1, 4, 9, and 16 are perfect squares. 3 and 11 are not. Example 1: Input: n = 12 Output: 3 Explanation: 12 = 4 + 4 + 4 Example...
Problem 1: Minimum Operations to Make Two Strings Equal Given two strings s and t, determine the minimum number of operations required to make them identical by deleting characters from either string. The approach involves identifying the longest common subsequence (LCS) between the two strings. Onc...
Problem Statement A tree with (n) nodes has two weights (a) and (b) per node, initailly set to (0). At each step, you can toggle the (b) value of at most one node. For nodes with (b = 1), their (a) values are toggled, followed by toggling thier (b) values and their parent's (b) values (if the parent...
A specialized variant of the Sieve of Eratosthenes can simultaneously tag integer primality and record the count of prime factors for each composite. This technique is particularly effective when searching for numbers within a range whose total number of prime factors (with multiplicity) equals a gi...
343. Integer Break Given a positive integer n, break it into the sum of k positive integers (k >= 2) and maximzie the product of those integers. Return the maximum product you can get. Example 1: Input: n = 2 Output: 1 Explanation: 2 = 1 + 1, 1 × 1 = 1. Example 2: Input: n = 10 Output: 36 Explana...
Longest Increasing Subsequence (LeetCode 300) To find the length of the longest strictly increasing subsequence, define dp[i] as the length of the longest increasing subsequence ending at index i. Initialize all entries to 1. For each element, compare it with all previous elements; if the current el...