leetcode486 Predict the Winner

Posted 王宜鸣

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了leetcode486 Predict the Winner相关的知识,希望对你有一定的参考价值。

思路:

博弈。

实现:

 1 class Solution 
 2 {
 3 public:
 4     
 5     bool PredictTheWinner(vector<int>& nums) 
 6     {
 7         int dp[21][21];
 8         int n = nums.size();
 9         for (int i = 0; i < n; i++) dp[i][i] = nums[i];
10         for (int i = n - 1; i >= 0; i--)
11         {
12             for (int j = i + 1; j < n; j++)
13             {
14                 dp[i][j] = max(nums[i] - dp[i + 1][j], nums[j] - dp[i][j - 1]);
15             }
16         }
17         return dp[0][n - 1] >= 0;
18     }
19 };

 

以上是关于leetcode486 Predict the Winner的主要内容,如果未能解决你的问题,请参考以下文章

[Leetcode] DP-- 486. Predict the Winner

[leetcode]Minimax-486. Predict the Winner

leetcode486 Predict the Winner

486. Predict the Winner

486. Predict the Winner

LC 486. Predict the Winner