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)


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