USACO08MAR River Crossing S - Complete Knapsack and Interval DP Solutions
Problem Link
Luogu P2904 [USACO08MAR] River Crossing S
Approach 1: Copmlete Knapsack DP
First, observe the problem constraints. We need to transport all (n) cows across the river, minimizing the total time. Suppose we make (k) trips, and on the (i)-th trip we take (a_i) cows. Then (a_1 + a_2 + \dots + a_k = n). This can be viewed as having (n) ...
Posted on Thu, 30 Jul 2026 16:26:47 +0000 by nblackwood
Advanced Re-rooting Dynamic Programming Walkthrough
Re-rooting DP is a tree-DP variant that looks intimidating at first, yet becomes very mechenical once the pattern is recognized. The following problems illustrate the key techniques.
Problem 1 – USACO 2012 FEB "Nearby Cows"
Task: for every node i compute the sum of weights of all nodes whose distance to i is at most K.
Constraints: n ...
Posted on Wed, 29 Jul 2026 16:38:52 +0000 by daf_cr
Solving the Watchcow Patrol Problem with Eulerian Circuit
Problem Statement
Farmer John has N farms (2 ≤ N ≤ 10^4) connected by M roads (1 ≤ M ≤ 5×10^4). Multiple roads between the same pair of farms are allowed.
Bassie starts patrolling from farm 1. Every road must be traversed exactly once in each direction, and the path must end back at farm 1.
Output any valid sequence of farms that satisfies the ...
Posted on Tue, 07 Jul 2026 16:41:18 +0000 by tha_mink