-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathSolution879.cs
42 lines (35 loc) · 1.01 KB
/
Solution879.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
using System.Text;
using LeetCode.DataStructures;
namespace LeetCode.Solutions;
public class Solution879
{
/// <summary>
/// 879. Profitable Schemes - Hard
/// <a href="https://leetcode.com/problems/profitable-schemes">See the problem</a>
/// </summary>
public int ProfitableSchemes(int n, int minProfit, int[] group, int[] profit)
{
int mod = 1_000_000_007;
int len = group.Length;
int[,] dp = new int[n + 1, minProfit + 1];
dp[0, 0] = 1;
for (int i = 0; i < len; i++)
{
int g = group[i];
int p = profit[i];
for (int j = n; j >= g; j--)
{
for (int k = minProfit; k >= 0; k--)
{
dp[j, k] = (dp[j, k] + dp[j - g, Math.Max(0, k - p)]) % mod;
}
}
}
int result = 0;
for (int i = 0; i <= n; i++)
{
result = (result + dp[i, minProfit]) % mod;
}
return result;
}
}