Wael is a well known stock market trader. Wael owes his success to his foresight. If…
- User
Wael is a well known stock market trader. Wael owes his success to his foresight. If Wael invests in day 1, he will earn A[1] dollars, if he invests at day 2 he will earn A[2] dollars, and so on until day N.
He has to choose a sub-sequence of days (not necessarily consecutive) to invest in stocks such that the following conditions are met:
The investment on Nth day must be made. He can invest at day i after investing at day j only if i - j <= D. Wael allows you to invest along with him if A[i] is strictly larger than all A[j] days in which he had previously invested for all days (1 <= j < i).
You need to find the maximum possible number of days on which Wael will allow you to invest with him.
Constraints:
1 <= N <= 400 1 <= D <= N 1 <= A[i] <= 10^9 Examples: Example 1. Input: N = 5, D = 5, A = [1, 200, 30, 40, 20]. Output: 3 Explanation: There are 5 possible days when investments can be made. But the most optimal sub-sequence is: {1, 30, 40, 20} out of which A[i] values for days when Wael will allow you to invest is {1, 30, 40}. So Ans = 3.
Example 2. Input: N = 5, D = 2, A = [100, 200, 100, 100, 300] Output: 3 Explanation: Most optimal - [100, 200, 100, 300] Allowed - [100, 200, 300] So Ans = 3
Example 3. Input: N = 7, D = 1, A = [100, 600, 600, 200, 300, 500, 500] Output: 3 Explanation: Most optimal - [200, 300, 500, 500] Allowed - [200, 300, 500] So Ans = 3
- Assistant
To solve this problem, we need to find the longest valid subsequence of days where Wael will allow you to invest. The conditions for the subsequence are:
- User
in cpp
- Assistant
To implement the solution in C++, we'll follow the same dynamic programming approach as outlined earlier. Below is the C++ code that addresses the problem:
cpp - User
its wrong
- Assistant
- User
Scientific Competition Problem There is a scientific competition held every year in which students participate in the form of teams, and the team that solves all the problems wins. We know that every student has power 𝑃 𝑖 P i
in a subject 𝑆 𝑖 S i
.
It is given that quiz questions will demand powers of at least 𝑄 𝑝 𝑗 Qp j
in subject 𝑗 j (where 𝑗 j is from 1 to 𝐾 K). If there are two students with powers 𝑋 X and 𝑌 Y in subject 𝑍 Z, the power of the team in that subject will be 𝑋 + 𝑌 X+Y. You have 𝑁 N students and want to choose from them a team that can solve all the problems of the competition and be composed of as few students as possible. It is mandatory that you choose a successive subgroup while selecting a team.
- Assistant
- User
use LIS code with condition for it
- Assistant