scala recursion with memoization
scala []\nobject Solution {\n  import scala.util.chaining._\n  def maxScore(n: Int, k: Int, stayScore: Array[Array[Int]], travelScore: Array[Array[Int]]): Int =
```scala []\nobject Solution {\n  import scala.util.chaining._\n  def maxScore(n: Int, k: Int, stayScore: Array[Array[Int]], travelScore: Array[Array[Int]]): Int = {\n    val cache = collection.mutable.Map.empty[(Int,Int),Int]\n    def f(city: Int, day: Int): Int = cache.getOrElse((city,day),\n      if(day>=k) 0 else Iterator.range(0,n).map{case i =>\n        (if(i==city) stayScore(day)(city) else travelScore(city)(i)) + f(i,day+1)\n      }.max).tap(rc => cache((city,day)) = rc)\n    Iterator.range(0,n).map{j => f(j,0)}.max\n  }\n}\n```
[]