题目:
https://leetcode-cn.com/problems/predict-the-winner/
代码:
class Solution {
public:
bool PredictTheWinner(vector<int>& nums) {
int n=nums.size();
int arr[n][n];
for(int i=0;i<n;i++) arr[i][i]=nums[i];
for(int i=1;i<n;i++){
for(int j=0;i+j<n;j++){
arr[j][i+j]=max(nums[j]-arr[j+1][i+j],nums[i+j]-arr[j][i+j-1]);
}
}
return arr[0][n-1]>=0;
}
};
思路:动态规划