← DiffPush

Ninja's Training

Standard Bar Dynamic Programming · 2D DP O(n) · O(1)

The Cadet's Rotating Drill

A trainee runs an n-day conditioning camp built around three stations — endurance, sparring, and tactics — each awarding a daily score. Regulations forbid repeating the same station two days in a row so every skill develops evenly. The coaching staff wants the highest possible total score over the camp, so the scheduler must pick one station per day without back-to-back repeats.

Input: An integer n and an n x 3 matrix points, where points[i][j] is the score for station j on day i.

Output: Return the maximum total score over n days with no station chosen on consecutive days.

Constraints

Examples

Example 1

Input: {"n":3,"points":[[1,2,5],[3,1,1],[3,3,3]]}
Output: 11
Station 2 on day 0 (5), station 0 on day 1 (3), station 1 on day 2 (3) — total 11.

Example 2

Input: {"n":2,"points":[[10,50,1],[5,100,11]]}
Output: 110
Station 0 on day 0 (10), then station 1 on day 1 (100) — total 110.

Solve this in your browser →

Also on LeetCode ↗