We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent a95af4a commit 1a42bc4Copy full SHA for 1a42bc4
2403-minimum-time-to-kill-all-monsters.js
@@ -0,0 +1,30 @@
1
+/**
2
+ * @param {number[]} power
3
+ * @return {number}
4
+ */
5
+const minimumTime = function(power) {
6
+ const n = power.length
7
+ const limit = 1 << n
8
+ const dp = new Array(limit).fill(Infinity)
9
+ dp[0] = 0
10
+ for(let mask = 1; mask < limit; mask++) {
11
+ const k = cnt(mask)
12
+ for(let i = 0; i < n; i++) {
13
+ if((mask >> i) & 1) {
14
+ dp[mask] = Math.min(dp[mask], dp[mask - (1 << i)] + Math.ceil(power[i] / k) )
15
+ }
16
17
18
+ // console.log(dp)
19
+ return dp[limit - 1]
20
+
21
+ function cnt(num) {
22
+ let res = 0
23
+ while(num) {
24
+ if(num & 1) res++
25
+ num = num >> 1
26
27
28
+ return res
29
30
+};
0 commit comments