Javascript - DP
Code\njavascript []\n/**\n * @param {number} n\n * @param {number} k\n * @param {number[][]} stayScore\n * @param {number[][]} travelScore\n * @return {number}\
# Code\n```javascript []\n/**\n * @param {number} n\n * @param {number} k\n * @param {number[][]} stayScore\n * @param {number[][]} travelScore\n * @return {number}\n */\nvar maxScore = function (n, k, stayScore, travelScore) {\n  const dp = new Array(k).fill().map((_) => new Array(n).fill());\n  let ans = 0;\n  for (let city = 0; city < n; city++) {\n    const result = helper(dp, city, 0, n, k, stayScore, travelScore);\n    ans = Math.max(ans, result);\n  }\n\n  return ans;\n};\n\nfunction helper(dp, city, day, n, k, stayScore, travelScore) {\n  if (day >= k) return 0;\n  if (dp[day][city] !== undefined) return dp[day][city];\n\n  // stay\n  let maxPoints =\n    stayScore[day][city] +\n    helper(dp, city, day + 1, n, k, stayScore, travelScore);\n\n  // move\n  for (let nextCity = 0; nextCity < n; nextCity++) {\n    if (city === nextCity) continue;\n    const next = helper(dp, nextCity, day + 1, n, k, stayScore, travelScore);\n    maxPoints = Math.max(maxPoints, travelScore[city][nextCity] + next);\n  }\n\n  return (dp[day][city] = maxPoints);\n}\n\n```
[]