Kefa and Dishes
HardRating 1800CodeforcesAdvanced DP (Bitmask, Digit, Interval)
Approach hintTry it first, then revealHide
Let dp[mask][last] be the best satisfaction after eating the dishes in mask ending with last. Adding dish j contributes a[j] plus the bonus of the rule for (last, j). Read answers from masks with m bits.