today's leetcode weekly contest number 298 4th question

Правка en1, от anshu2002, 2022-06-19 14:16:01
class Solution {
public:
    vector<vector<long long>>dp;
    void solve(int m, int n){
        for(int i=1;i<=m/2;i++){
            solve(i,n);
            solve(m-i,n);
            dp[m][n]=max(dp[m][n],dp[i][n]+dp[m-i][n]);
        }
        for(int i=1;i<=n/2;i++){
            solve(m,i);
            solve(m,n-i);
            dp[m][n]=max(dp[m][n],dp[m][i]+dp[m][n-i]);
        }
    }
    long long sellingWood(int m, int n, vector<vector<int>>& prices) {
        dp = vector<vector<long long>>(m+1,vector<long long>(n+1,0));
        for(auto it:prices){
            dp[it[0]][it[1]]=it[2];
        }
        solve(m,n);
        return dp[m][n];
    }
};

this was my approach , showing tle . Why ?? link to the problem

Теги contest, leetcode, #leetcode, weekly

История

 
 
 
 
Правки
 
 
  Rev. Язык Кто Когда Δ Комментарий
en2 Английский anshu2002 2022-06-19 15:33:47 34 Tiny change: 'wood/)\n\n\n' -> 'wood/)\n\nPlease somebody correct my mistake\n'
en1 Английский anshu2002 2022-06-19 14:16:01 882 Initial revision (published)