Maximum Points Tourist Can Earn - Problem
Maximum Points Tourist Can Earn
Imagine you're planning the ultimate sightseeing adventure! 🏙️ You have
Each day, you face an exciting decision:
• Stay in your current city and earn
• Travel to a different city and earn
All cities are directly connected, so you can travel anywhere! Your mission is to find the maximum possible points you can earn during your
Goal: Return the maximum points achievable starting from any city.
Input: Two integers
Output: Maximum points possible
Imagine you're planning the ultimate sightseeing adventure! 🏙️ You have
n cities to explore over exactly k days, and you want to maximize your experience points.Each day, you face an exciting decision:
• Stay in your current city and earn
stayScore[day][city] points• Travel to a different city and earn
travelScore[currentCity][destinationCity] pointsAll cities are directly connected, so you can travel anywhere! Your mission is to find the maximum possible points you can earn during your
k-day journey.Goal: Return the maximum points achievable starting from any city.
Input: Two integers
n, k and two 2D arrays stayScore, travelScoreOutput: Maximum points possible
Input & Output
example_1.py — Basic Case
$
Input:
n = 2, k = 1
stayScore = [[2, 3]]
travelScore = [[0, 2], [1, 0]]
›
Output:
3
💡 Note:
With only 1 day, we can either start in city 0 and stay (2 points) or start in city 1 and stay (3 points). Starting in city 1 and staying gives maximum 3 points.
example_2.py — Travel vs Stay
$
Input:
n = 2, k = 2
stayScore = [[2, 3], [1, 4]]
travelScore = [[0, 5], [3, 0]]
›
Output:
8
💡 Note:
Optimal path: Start in city 0, travel to city 1 (5 points), then stay in city 1 (4 points). Total: 5 + 4 = 9 points. Wait, let me recalculate: Start city 1, stay (3 points), stay again (4 points) = 7. Or start city 0, travel to city 1 (5 points), stay (4 points) = 9. But we need to check all starting positions properly.
example_3.py — Multiple Cities
$
Input:
n = 3, k = 2
stayScore = [[1, 2, 3], [4, 5, 6]]
travelScore = [[0, 2, 1], [3, 0, 2], [1, 4, 0]]
›
Output:
9
💡 Note:
Start in city 2, stay day 0 (3 points), stay day 1 (6 points). Total: 3 + 6 = 9 points. This is optimal among all possible starting cities and action sequences.
Constraints
- 1 ≤ n ≤ 200
- 1 ≤ k ≤ 200
- n × k ≤ 1000
- 0 ≤ stayScore[i][j] ≤ 106
- 0 ≤ travelScore[i][j] ≤ 106
- travelScore[i][i] = 0 (no points for staying via travel)
Visualization
Tap to expand
Understanding the Visualization
1
Choose Starting City
Pick any city to begin your k-day adventure
2
Daily Decision
Each day: stay and get local experience points, or travel for journey points
3
Build Optimal Path
Use DP to remember best score reachable at each (day, city) combination
4
Find Maximum
Return the highest score achievable across all starting cities
Key Takeaway
🎯 Key Insight: This is a classic dynamic programming problem where we build the optimal solution by making the best local decisions at each step, using memoization to avoid redundant calculations.
💡
Explanation
AI Ready
💡 Suggestion
Tab
to accept
Esc
to dismiss
// Output will appear here after running code