Current player has two choices: take nums[i] (left) or take nums[j] (right). If I take left: I gain nums[i], then opponent plays optimally on [i+1,j]. My net: nums[i]−dp[i+1][j]. The subtraction is because opponent's best difference becomes my disadvantage.
If I take right: I gain nums[j], opponent plays on [i,j−1]. My net: nums[j]−dp[i][j−1]. I pick the better option: dp[i][j]=max(nums[i]−dp[i+1][j],nums[j]−dp[i][j−1]).