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