DP (0/1 Knapsack)+ Standard DFS | C++
IntuitionApproachDP (0/1 Knapsack)+ Standard DFSComplexity
Time complexity: (N^2) * K

Space complexity: N^2
Code
# Intuition
<!-- Describe your first thoughts on how to solve this problem. -->

# Approach
<!-- Describe your approach to solving the problem. -->
DP (0/1 Knapsack)+ Standard DFS 

# Complexity
- Time complexity: (N^2) * K
<!-- Add your time complexity here, e.g. $$O(n)$$ -->

- Space complexity: N^2
<!-- Add your space complexity here, e.g. $$O(n)$$ -->


# Code
```cpp []
class Solution {
public:
    vector<vector<int>> stay;
    vector<vector<pair<int, int>>> adj;
    int K;
    int dp[203][203];
    int go(int u, int k) {
        if (k >= K)
            return 0;
        if(dp[u][k] != -1)
            return dp[u][k];
        int st = stay[k][u] + go(u, k + 1);
        int nst = 0;
        for (auto& x : adj[u]) {
            int v = x.first, w = x.second;
            nst = max(nst, w + go(v, k + 1));
        }
        return dp[u][k] = max(nst, st);
    }
    int maxScore(int n, int k, vector<vector<int>>& stay,
                 vector<vector<int>>& t) {
        adj.resize(n + 1);
        this->stay = stay;
        this->K = k;
        memset(dp, -1, sizeof dp);
        for (int i = 0; i < size(t); i++) {
            for (int j = 0; j < size(t[0]); j++) {
                adj[i].push_back({j, t[i][j]});
            }
        }
        int ans = 0;
        for (int i = 0; i < n; i++) {
            ans = max(ans, go(i, 0));
        }
        return ans;
    }
};
```
['C++']