Profitable Schemes
Problem Statement
A gang has n members and a list of crimes. Crime i needs group[i] members and earns profit[i]. A member who joins one crime cannot join another.
A scheme is any set of crimes where the members needed, added up, are at most n, and the profit, added up, is at least minProfit. Count the schemes. The empty set of crimes is a scheme when minProfit is 0.
Return the count modulo 10^9 + 7.
n, the number of members. minProfit, the profit goal. group, the members each crime needs. profit, the profit of each crime (the same length as group).
The number of schemes with at least minProfit profit and at most n members in total, modulo 10^9 + 7.
Crime 1 alone earns 3, which is enough. Crimes 0 and 1 together earn 5 and use 4 members, which fits in 5. Crime 0 alone earns only 2, so it does not count.
Every crime alone already earns at least 5, and all three together use exactly 10 members. So every set with at least one crime counts: 2³ − 1 = 7 schemes.
- • 1 ≤ n ≤ 100
- • 0 ≤ minProfit ≤ 100
- • 1 ≤ group.length ≤ 100
- • 1 ≤ group[i] ≤ 100
- • profit.length == group.length
- • 0 ≤ profit[i] ≤ 100
Pattern Recognition Clues
Recognising these key signals in the problem description immediately identifies the pattern:
Approach Complexity Ladder
Recurse over the crimes: skip each one, or do it if its members fit; count the finished schemes that earn enough
The same recursion, with profit capped at minProfit and each (crime, members, profit) state solved once
dp[m][p] counts the schemes using at most m members with capped profit p; for each crime, members go from high to low
Walk the crimes in order. For each crime, either skip it, or do it when its members still fit. At the end, count the chosen set if its profit reaches minProfit. Every subset of crimes is one path, so every scheme is counted once.
Recognition rule for this sub-pattern:
Unlock Complete Visual Walkthrough & Optimal C++
The interactive animated dry-run player, optimized C++ implementation, state invariant derivations, and edge-case breakdown for this question are part of Brute2Best Pro. The anchor question of every sub-pattern is completely free.
First anchor question per pattern, Part 1 LLD & Module 1 C++ basics are 100% Free forever.
How this concept connects to System Design & C++ Systems
Top engineering interviews test whether you understand how algorithms like DP — Knapsack translate into production architectures and low-level memory mechanics.
Foundations: Object-Oriented Principles in C++23
Class invariants, pure virtual interfaces, and RAII smart pointers.
Food Delivery System (Zomato Architecture)
Real-world machine coding application of algorithms and design patterns.
Pointers vs References Deep Dive
Pointer arithmetic and memory layout under the hood.
Virtual Method Table (vtable) & Memory Layout
Polymorphism, vptr overhead, and multiple inheritance in memory.