Skip to content

Commit 7798136

Browse files
authored
Create 879-profitable-schemes.js
1 parent e29d86b commit 7798136

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

879-profitable-schemes.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
/**
2+
* @param {number} G
3+
* @param {number} P
4+
* @param {number[]} group
5+
* @param {number[]} profit
6+
* @return {number}
7+
*/
8+
const profitableSchemes = function(G, P, group, profit) {
9+
const dp = Array.from({ length: P + 1 }, () => new Array(G + 1).fill(0))
10+
dp[0][0] = 1
11+
let res = 0,
12+
mod = 10 ** 9 + 7
13+
for (let k = 0; k < group.length; k++) {
14+
let g = group[k],
15+
p = profit[k]
16+
for (let i = P; i >= 0; i--)
17+
for (let j = G - g; j >= 0; j--)
18+
dp[Math.min(i + p, P)][j + g] =
19+
(dp[Math.min(i + p, P)][j + g] + dp[i][j]) % mod
20+
}
21+
for (let x of dp[P]) res = (res + x) % mod
22+
return res
23+
}

0 commit comments

Comments
 (0)