Profitable Schemes - Problem
Criminal Organization Planning Challenge

You're managing a criminal organization with n members who need to plan their operations strategically. You have a list of potential crimes, where each crime i:
โ€ข Generates profit[i] money
โ€ข Requires exactly group[i] members to execute

Important constraint: Each member can only participate in one crime - no member can be involved in multiple operations.

Your goal is to find how many different profitable schemes exist. A profitable scheme is any combination of crimes that:
1. Generates at least minProfit total profit
2. Uses at most n total members

Since the answer can be extremely large, return it modulo 10^9 + 7.

Example: With 3 members, minProfit=2, profits=[2,3,1], groups=[2,1,1]
You could choose crime 0 (profit=2, uses 2 members) OR crimes 1+2 (profit=4, uses 2 members) = 2 schemes

Input & Output

example_1.py โ€” Basic Case
$ Input: n = 5, minProfit = 3, group = [2,2], profit = [2,3]
โ€บ Output: 2
๐Ÿ’ก Note: We can form 2 profitable schemes: choose crime 1 alone (profit=3, members=2) OR choose both crimes (profit=5, members=4). Both satisfy minProfit โ‰ฅ 3 and members โ‰ค 5.
example_2.py โ€” Multiple Options
$ Input: n = 10, minProfit = 5, group = [2,3,5], profit = [6,7,8]
โ€บ Output: 7
๐Ÿ’ก Note: Multiple combinations work: {0}, {1}, {2}, {0,1}, {0,2}, {1,2}, {0,1,2}. Each achieves profit โ‰ฅ 5 with members โ‰ค 10.
example_3.py โ€” Edge Case
$ Input: n = 1, minProfit = 1, group = [1,1,1], profit = [1,1,1]
โ€บ Output: 3
๐Ÿ’ก Note: With only 1 member available, we can choose any single crime. Each crime uses exactly 1 member and generates profit 1, meeting our minimum requirement.

Constraints

  • 1 โ‰ค n โ‰ค 100
  • 0 โ‰ค minProfit โ‰ค 100
  • 1 โ‰ค group.length โ‰ค 100
  • 1 โ‰ค group[i] โ‰ค 100
  • 0 โ‰ค profit[i] โ‰ค 100
  • Note: Each member can participate in at most one crime

Visualization

Tap to expand
๐ŸŽฏ Profitable Schemes: Heist Planning Strategy๐Ÿ‘ฅ Available CrewABCDEn = 5 members๐Ÿ’ฐ Target Profitโ‰ฅ $3Minimum RequiredminProfit = 3๐ŸŽฒ Available HeistsH1: $2, 2๐Ÿ‘ฅH2: $3, 2๐Ÿ‘ฅChoose combinationsto maximize schemes๐Ÿงฎ Dynamic Programming Solutiondp[members][profit] = number of ways to use exactly 'members' and get at least 'profit'Members\Profit0123010002101141001Valid Schemes Found:1. Heist 2 only: $3, 2๐Ÿ‘ฅ2. Both heists: $5, 4๐Ÿ‘ฅAnswer: 2 schemesโšก Optimized with 3D DP: O(n ร— m ร— minProfit) time complexityGreen=Base case, Blue=Updated states, Orange=Final answer contributor
Understanding the Visualization
1
Setup Crew
You have n members available and need at least minProfit total
2
Evaluate Heists
Each heist has specific member requirements and profit potential
3
Dynamic Planning
Use DP to count all valid combinations efficiently
4
Count Schemes
Sum all ways that meet profit goal with available crew
Key Takeaway
๐ŸŽฏ Key Insight: Use 3D DP to efficiently count all valid combinations by tracking members used and minimum profit achieved, avoiding the exponential complexity of brute force enumeration.
Asked in
Google 45 Amazon 38 Meta 32 Microsoft 28
42.3K Views
Medium Frequency
~25 min Avg. Time
1.2K Likes
Ln 1, Col 1
Smart Actions
๐Ÿ’ก Explanation
AI Ready
๐Ÿ’ก Suggestion Tab to accept Esc to dismiss
// Output will appear here after running code
Code Editor Closed
Click the red button to reopen