Simple dp solution
\njava []\nclass Solution {\n    HashSet<Integer>hs;\n    Integer[][]dp;\n    public int maxScore(int n, int k, int[][] s, int[][] t) {\n        int ans=0;\n   
\n```java []\nclass Solution {\n    HashSet<Integer>hs;\n    Integer[][]dp;\n    public int maxScore(int n, int k, int[][] s, int[][] t) {\n        int ans=0;\n        hs=new HashSet<>();\n        dp=new Integer[n][k];\n      for(int i=0;i<n;i++){\n             hs.add(i);\n            ans=Math.max(ans,f(i,0,k,s,t));\n            hs.remove(i);\n      }\n        return ans;\n    }\n    public int f(int c,int d,int k,int[][]s,int[][]t){\n        if(d>=k)return 0;\n        if(dp[c][d]!=null)return dp[c][d];\n           int ans=f(c,d+1,k,s,t)+s[d][c];\n           for(int i=0;i<t.length;i++){\n            if(i==c)continue;\n          //  if(hs.contains(i))continue;\n            //hs.add(i);\n             ans=Math.max(ans,f(i,d+1,k,s,t)+t[c][i]);\n             //hs.remove(i);\n           }\n           return dp[c][d]=ans;\n    }\n}\n```
[]