Skip to content

Commit 473bb11

Browse files
committed
2 problem
1 parent 3e1c0b7 commit 473bb11

File tree

3 files changed

+37
-1
lines changed

3 files changed

+37
-1
lines changed

README.md

+3-1
Original file line numberDiff line numberDiff line change
@@ -226,7 +226,9 @@ Golang solution for leetcode. For each problem, there is a simple *_test.go to t
226226
#### [306. Additive Number](https://github.com/hitzzc/go-leetcode/tree/master/additive_number)
227227
#### [307. Range Sum Query - Mutable](https://github.com/hitzzc/go-leetcode/tree/master/range_sum_query_mutable)
228228
#### [309. Best Time to Buy and Sell Stock with Cooldown](https://github.com/hitzzc/go-leetcode/tree/master/best_time_to_buy_and_sell_stock_with_cooldown)
229-
#### [310. Minimum Height Trees](https://github.com/hitzzc/go-leetcode/tree/master/minimum_height_trees)
229+
#### [312. Burst Balloons](https://github.com/hitzzc/go-leetcode/tree/master/burst_balloons)
230+
#### [313. Super Ugly Number](https://github.com/hitzzc/go-leetcode/tree/master/super_ugly_number)
231+
230232

231233

232234

burst_balloons/burst_balloons.cpp

+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public:
3+
int maxCoins(vector<int>& nums) {
4+
nums.insert(nums.begin(), 1);
5+
nums.push_back(1);
6+
vector<vector<int>> matrix(nums.size(), vector<int>(nums.size(), 0));
7+
for (int k = 2; k < nums.size(); ++k) {
8+
for (int low = 0; low < nums.size()-k; ++low) {
9+
int high = low+k;
10+
for (int i = low+1; i < high; ++i) {
11+
matrix[low][high] = max(matrix[low][high], nums[low]*nums[i]*nums[high] + matrix[low][i] + matrix[i][high]);
12+
}
13+
}
14+
}
15+
return matrix[0][matrix.size()-1];
16+
}
17+
};
+17
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
class Solution {
2+
public:
3+
int nthSuperUglyNumber(int n, vector<int>& primes) {
4+
vector<int> dp(n, 1);
5+
vector<int> idxs(primes.size(), 0);
6+
for (int i = 1; i < n; ++i) {
7+
dp[i] = INT_MAX;
8+
for (int idx = 0; idx < idxs.size(); ++idx) {
9+
dp[i] = min(dp[i], primes[idx]*dp[idxs[idx]]);
10+
}
11+
for (int idx = 0; idx < idxs.size(); ++idx) {
12+
if (dp[i] == primes[idx] * dp[idxs[idx]]) ++idxs[idx];
13+
}
14+
}
15+
return dp.back();
16+
}
17+
};

0 commit comments

Comments
 (0)