Standard DP || C++ || Recursion->Memoization->Tabulation->Space Optimization
Intuition\n Describe your first thoughts on how to solve this problem. \n\n# Approach\n Describe your approach to solving the problem. \n\n# Complexity\n- Time 
# Intuition\n<!-- Describe your first thoughts on how to solve this problem. -->\n\n# Approach\n<!-- Describe your approach to solving the problem. -->\n\n# Complexity\n- Time complexity:\n<!-- Add your time complexity here, e.g. $$O(n)$$ -->\n\n- Space complexity:\n<!-- Add your space complexity here, e.g. $$O(n)$$ -->\n\n# Code\n**Recursion**\n```cpp []\nclass Solution {\npublic:\n    int K;\n    int N;\n    int dfs(int curr,int day,vector<vector<int>>& stayScore,vector<vector<int>>& travelScore){\n        if (day==K) return 0;\n        int stay=stayScore[day][curr]+dfs(curr,day+1,stayScore,travelScore);\n        int travel=0;\n        for (int i=0;i<N;i++){\n            if(i!=curr){\n                travel=max(travel,travelScore[curr][i]+dfs(i,day+1,stayScore,travelScore));\n            }\n        }\n        return max(stay,travel);\n    }\n    int maxScore(int n, int k, vector<vector<int>>& stayScore, vector<vector<int>>& travelScore) {\n        int maxi=0;\n        K=k;\n        N=n;\n        for (int i=0;i<n;i++){\n            maxi=max(maxi,dfs(i,0,stayScore,travelScore));\n        }\n        return maxi;\n    }\n};\n```\n# Code\n**Memoization**\n```cpp []\nclass Solution {\npublic:\n    int K;\n    int N;\n    int dfs(int curr,int day,vector<vector<int>>& stayScore,vector<vector<int>>& travelScore,vector<vector<int>>&dp){\n        if (day==K) return 0;\n        if (dp[curr][day]!=-1) return dp[curr][day];\n        int stay=stayScore[day][curr]+dfs(curr,day+1,stayScore,travelScore,dp);\n        int travel=0;\n        for (int i=0;i<N;i++){\n            if(i!=curr){\n                travel=max(travel,travelScore[curr][i]+dfs(i,day+1,stayScore,travelScore,dp));\n            }\n        }\n        return dp[curr][day]=max(stay,travel);\n    }\n    int maxScore(int n, int k, vector<vector<int>>& stayScore, vector<vector<int>>& travelScore) {\n        int maxi=0;\n        K=k;\n        N=n;\n        vector<vector<int>>dp(n,vector<int>(k,-1));\n        for (int i=0;i<n;i++){\n            maxi=max(maxi,dfs(i,0,stayScore,travelScore,dp));\n        }\n        return maxi;\n    }\n};\n```\n# Code\n**Tabulation**\n```cpp []\nclass Solution {\npublic:\n    int maxScore(int n, int k, vector<vector<int>>& stayScore, vector<vector<int>>& travelScore) {\n        int maxi=0;\n        vector<vector<int>>dp(n,vector<int>(k+1,0));\n        for (int day=k-1;day>=0;day--){\n            for (int curr=0;curr<n;curr++){\n                    int stay=stayScore[day][curr]+dp[curr][day+1];\n                    int travel=0;\n                    for (int i=0;i<n;i++){\n                    if(i!=curr){\n                        travel=max(travel,travelScore[curr][i]+dp[i][day+1]);\n                      }\n                    }\n                    dp[curr][day]=max(stay,travel);\n            }\n        }\n        for (int i=0;i<n;i++){\n            maxi=max(maxi,dp[i][0]);\n        }\n        return maxi;\n    }\n};\n```\n# Code\n**Space Optimization**\n```cpp []\nclass Solution {\npublic:\n    int maxScore(int n, int k, vector<vector<int>>& stayScore, vector<vector<int>>& travelScore) {\n        int maxi=0;\n        vector<int>prev(n);\n        for (int day=k-1;day>=0;day--){\n            vector<int>next(n);\n            for (int curr=0;curr<n;curr++){\n                    int stay=stayScore[day][curr]+prev[curr];\n                    int travel=0;\n                    for (int i=0;i<n;i++){\n                    if(i!=curr){\n                        travel=max(travel,travelScore[curr][i]+prev[i]);\n                      }\n                    }\n                    next[curr]=max(stay,travel);\n            }\n            prev=next;\n        }\n        for (int i=0;i<n;i++){\n            maxi=max(maxi,prev[i]);\n        }\n        return maxi;\n    }\n};\n```
[]