How to solve the problem of profit Planning by golang leetcode dynamic Planning
This article mainly introduces the golang brush leetcode dynamic planning how to solve the problem of profit planning, has a certain reference value, interested friends can refer to, I hope you can learn a lot after reading this article, the following let the editor take you to understand it.
There are G members in the gang who may commit all kinds of crimes.
The type I crime generates profits from profit [I], which requires the participation of group [I] members.
Let's call any subset of these crimes a profit plan, which generates at least P profits.
How many options are available? Because the answer is large, it returns a value of 10 ^ 9 + 7.
Example 1:
Input: G = 5, P = 3, group = [2jue 2], profit = [2pr 3]
Output: 2
Explanation:
Generate at least 3% of the profit, the gang can commit crime 0 and crime 1, or only crime 1.
In general, there are two options.
Example 2:
Input: G = 10, P = 5, group = [2Jing 3JEI 5], profit = [6Jing 7JI 8]
Output: 7
Explanation:
Generate at least 5% profit, as long as they commit one of these crimes, so the gang can commit any crime.
There are seven possible plans: (0), (1), (2), (0meme1), (0meme2), (1meme2), and (0meme1mem2).
Tip:
one