Skip to main content
LeetCode 879, Hard. Topics: Array, Dynamic Programming, Knapsack Problem, 0-1 Knapsack. View on LeetCode. Generate this problem as a practice environment: tested reference solution, 13 parametrized pytest cases, and a playground notebook:

Problem

There is a group of <code>n</code> members, and a list of various crimes they could commit. The <code>ith</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’t participate in another crime.</p> <p>Let’s call a <em>profitable scheme</em> 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, return it <strong>modulo</strong> <code>10<sup>9</sup> + 7</code>.

Examples

Constraints

  • 1 <= n <= 100
  • 0 <= minProfit <= 100
  • 1 <= group.length <= 100
  • 1 <= group[i] <= 100
  • profit.length == group.length
  • 0 <= profit[i] <= 100

Solution

Reference implementation from solution.py on GitHub, full suite in test_solution.py:

Complexity

Tags

NeetCode All.
Last modified on September 7, 2026