leetcode

Solution to some Leetcode problems written in C++
git clone git://git.dimitrijedobrota.com/leetcode.git
Log | Files | Refs | README | LICENSE

1049.cpp (585B)


      1 class Solution {
      2     static int dp[6001][31];
      3 
      4   public:
      5     Solution() { memset(dp, 0xFF, sizeof(dp)); }
      6     int lastStoneWeightII(const vector<int> &stones, int total = 0, int crnt = 0) const {
      7         if (crnt == size(stones)) return total >= 0 ? total : INT_MAX;
      8         if (dp[total + 3000][crnt] != -1) return dp[total + 3000][crnt];
      9         return dp[total + 3000][crnt] = min(lastStoneWeightII(stones, total + stones[crnt], crnt + 1),
     10                                             lastStoneWeightII(stones, total - stones[crnt], crnt + 1));
     11     }
     12 };
     13 
     14 int Solution::dp[6001][31];