C++| Tabulation | Beats 99%
Intuition\nThere could be several possible ways to reach a particular city on a particular day starting from a city. Given the constraints of the problem we can
# Intuition\nThere could be several possible ways to reach a particular city on a particular day starting from a city. Given the constraints of the problem we can try to exhaustively simulate these actions and find the maximum possible score.\n\n# Approach\nWe can solve this propblem using dynamic programming. We can break the problem down on time, we can solve for what we do on the first day , taking the starting points through all the cities then solve for the second day for all the cities and so on.\n\n# Complexity\n- Time complexity:\nO(k\\*n*n)\n\n- Space complexity:\nO(k*n)\n\n# Code\n```cpp []\nclass Solution {\npublic:\n    int maxScore(int n, int k, vector<vector<int>>& stayScore, vector<vector<int>>& travelScore) {\n        int dp[201][201];\n        memset(dp, 0 ,sizeof(dp));\n\n        // Iterating through the days\n        for(int day = 0; day < k; day++) {\n            // We could be at various cities at this point in time\n            for(int city = 0; city < n; city++) {\n                //We could either stay there or we could move to another city \n\n                // If we stay at the same place\n                dp[city][day + 1] = max(dp[city][day + 1], dp[city][day] + stayScore[day][city]);\n\n                // If we move at that day\n                for(int dest = 0; dest < n; dest++) {\n                    dp[dest][day + 1] = max(dp[dest][day + 1], dp[city][day] + travelScore[city][dest]);\n                }\n            }\n        }\n\n        int ans = INT_MIN;\n        //calculate max attainable score\n        for(int endDest = 0; endDest < n; endDest++) {\n            ans = max(ans, dp[endDest][k]);\n        }\n\n        return ans;\n    }\n};\n```
[]