standard DP
class Solution {\npublic:\n    int dp[205][205];\n    int solve(int i, int j,int &k,int &n,vector>& stayScore, vector>& travelScore)\n    {\n        if(j==k)\n 
class Solution {\npublic:\n    int dp[205][205];\n    int solve(int i, int j,int &k,int &n,vector<vector<int>>& stayScore, vector<vector<int>>& travelScore)\n    {\n        if(j==k)\n            return 0;\n        \n        if(dp[i][j] != -1)\n            return dp[i][j];\n        int ans=0;\n        ans=max(ans,stayScore[j][i]+solve(i,j+1,k,n,stayScore,travelScore));\n        for(int p=0;p<n;p++)\n        {\n            ans=max(ans,travelScore[i][p]+solve(p,j+1,k,n,stayScore,travelScore));\n        }\n        return dp[i][j]=ans;\n    }\n    int maxScore(int n, int k, vector<vector<int>>& stayScore, vector<vector<int>>& travelScore) {\n        memset(dp,-1,sizeof(dp));\n        int ans=0;\n        for(int i=0;i<n;i++)\n        {\n            ans=max(ans,solve(i,0,k,n,stayScore,travelScore));\n        }\n        \n        return ans;\n    }\n};
[]