其他分享
首页 > 其他分享> > 486. 预测赢家

486. 预测赢家

作者:互联网

class Solution {
      
public:
    bool PredictTheWinner(vector<int>& nums) {
	    int n = nums.size();
        vector<vector<int>>dp(n, vector<int>(n,0));
        return dfs(0, n-1, dp, nums)>=0;
    }
    
    int dfs(int begin, int end, vector<vector<int> > &dp, vector<int> &nums)
    {
        dp[begin][end]= (begin==end?nums[begin]:max(nums[begin]-dfs(begin+1, end, dp, nums), nums[end]-dfs(begin, end-1, dp, nums)));
        return dp[begin][end];
    }
};

 

标签:begin,end,预测,nums,int,赢家,vector,486,dp
来源: https://blog.csdn.net/Scarlett_Guan/article/details/99186853