← CSES Better

Count the Cows

USACO · 2021 · February · gold-3

Open official problem ↗
Ask AI

Open a hint-first prompt in a new AI chat. Grok may ask you to confirm before sending.

Open Claude Desktop

dynamic-programming

The organizer’s problem statement is available at the official source link.

sample trace

Count the Cows: dynamic programming walkthrough

Count the Cows: use the linked editorial?s dynamic programming idea on the published sample, then verify the displayed output.

Published input8 10 0 0 10 0 1 9 0 2 8 0 2 0 1 7 1 1 7 2 1 7 1000000000000000000 1000000000000000000 1000000000000000000modelAlgorithm ideaTrack smaller states that summarize partial solutions. For each state, combine the legal predecessor states; the full-task state gives the result.task resultExpected output11 0 4 3 1 2 2 1000000000000000001
  1. 1

    State

    Choose a compact value for each partial subproblem so later choices need only that summary.
  2. 2

    Transition

    Combine legal smaller states to compute reachability, a count, or an optimum for the next state.
  3. 3

    Finish

    Read the state representing the full task and compare it with the published sample output.
  4. 4

    Verify the sample

    Use the published sample output to check the result of this idea on the displayed input.
Tools
1
2
3
4
5
6
7
8
9
10
11
12
Draft saved locally
|12 lines, 156 chars

Run output

Run your code to see output.