USACO Gold 2016 December - Cow Checklist
Authors: Maggie Liu, Ryan Chou
Note that at any single point in time Farmer John will be at either a Holstein or a Guernsey, and will have the choice to either go to the next Holstein or Guernsey.
This suggests a DP. Let represent the minimum cumulative distance for Farmer John to visit the first Holsteins and the first Guernseys.
Then, Farmer John can either go to the next Holstein or the next Guernsey.
Implementation
Time Complexity:
C++
#include <cstdio>#include <iostream>#include <vector>using namespace std;using ll = long long;const ll MAX_D = 1e18;struct Coord {public:
Join the USACO Forum!
Stuck on a problem, or don't understand a module? Join the USACO Forum and get help from other competitive programmers!