Simple dp c++
Intuition\nJust checking all possible ways and taking the maximum.\n\n\n# Code\ncpp []\nclass Solution {\npublic:\nint f(int day,int curr,int k,vector<vector<in
# Intuition\nJust checking all possible ways and taking the maximum.\n\n\n# Code\n```cpp []\nclass Solution {\npublic:\nint f(int day,int curr,int k,vector<vector<int>>& stay, vector<vector<int>>& travel,vector<vector<int>>& dp){\n    if(day == k) return 0;\n    if(dp[curr][day] != -1) return dp[curr][day];\n\n    int x = f(day+1,curr,k,stay,travel,dp) + stay[day][curr];\n    int y = 0;\n    for(int i=0;i<travel.size();i++){\n        if(i != curr){\n            y = max(y,f(day+1,i,k,stay,travel,dp)+travel[curr][i]);\n        }\n    }\n\n    return dp[curr][day] = max(x,y);\n}\n    int maxScore(int n, int k, vector<vector<int>>& stayScore, vector<vector<int>>& travelScore) {\n        vector<vector<int>> dp(n+1,vector<int>(k+1,-1));\n        int ans = 0;\n        for(int i=0;i<n;i++){\n            ans = max(ans,f(0,i,k,stayScore,travelScore,dp));\n        }\n        return ans;\n    }\n};\n```
[]