Class Solution

java.lang.Object
g0801_0900.s0879_profitable_schemes.Solution

public class Solution extends Object
879 - Profitable Schemes.<p>Hard</p> <p>There is a group of <code>n</code> members, and a list of various crimes they could commit. The <code>i<sup>th</sup></code> crime generates a <code>profit[i]</code> and requires <code>group[i]</code> members to participate in it. If a member participates in one crime, that member can&rsquo;t participate in another crime.</p> <p>Let&rsquo;s call a <strong>profitable scheme</strong> any subset of these crimes that generates at least <code>minProfit</code> profit, and the total number of members participating in that subset of crimes is at most <code>n</code>.</p> <p>Return the number of schemes that can be chosen. Since the answer may be very large, <strong>return it modulo</strong> <code>10<sup>9</sup> + 7</code>.</p> <p><strong>Example 1:</strong></p> <p><strong>Input:</strong> n = 5, minProfit = 3, group = [2,2], profit = [2,3]</p> <p><strong>Output:</strong> 2</p> <p><strong>Explanation:</strong></p> <p>To make a profit of at least 3, the group could either commit crimes 0 and 1, or just crime 1.</p> <p>In total, there are 2 schemes.</p> <p><strong>Example 2:</strong></p> <p><strong>Input:</strong> n = 10, minProfit = 5, group = [2,3,5], profit = [6,7,8]</p> <p><strong>Output:</strong> 7</p> <p><strong>Explanation:</strong></p> <p>To make a profit of at least 5, the group could commit any crimes, as long as they commit one.</p> <p>There are 7 possible schemes: (0), (1), (2), (0,1), (0,2), (1,2), and (0,1,2).</p> <p><strong>Constraints:</strong></p> <ul> <li><code>1 <= n <= 100</code></li> <li><code>0 <= minProfit <= 100</code></li> <li><code>1 <= group.length <= 100</code></li> <li><code>1 <= group[i] <= 100</code></li> <li><code>profit.length == group.length</code></li> <li><code>0 <= profit[i] <= 100</code></li> </ul>
  • Constructor Details

    • Solution

      public Solution()
  • Method Details

    • profitableSchemes

      public int profitableSchemes(int n, int minProfit, int[] group, int[] profit)