Ask AI
Open a hint-first prompt in a new AI chat. Grok may ask you to confirm before sending.
Open Claude Desktopdynamic-programming
The organizer’s problem statement is available at the official source link.
sample trace
Cow Hopscotch: quadratic DP
For each cell, sum the path counts of strictly upper-left cells whose color differs; the DP grid shows the sample states.
colors
| 1 | 1 | 1 | 1 |
| 1 | 3 | 2 | 1 |
| 1 | 2 | 4 | 1 |
| 1 | 1 | 1 | 1 |
path Counts
| 1 | 0 | 0 | 0 |
| 0 | 1 | 1 | 0 |
| 0 | 1 | 2 | 2 |
| 0 | 0 | 2 | 5 |
start
11
goal
44
answer
5- 1
Define a state
dp[r][c] counts valid paths ending at cell (r,c). Start with one path at the top-left. - 2
Sum valid predecessors
For each cell, add states from strictly upper-left cells whose color differs from this cell. - 3
Read the destination
The DP matrix ends with 5 paths at the bottom-right, matching the sample output.
Tools
1
2
3
4
5
6
7
8
9
10
11
12
Draft saved locally
|12 lines, 156 charsRun output
Run your code to see output.