Question: Using C++, implement a function to solve this problem with dynamic programming, with the following function parameter: int solve(int n, int m); Sora has just
Using C++, implement a function to solve this problem with dynamic programming, with the following function parameter: int solve(int n, int m);

Sora has just received Slay the Spire, a roguelike video game from Shiro. In this game, the player needs to choose a difficulty level before starting a run, and Sora wants to figure out the most difficult level he's able to complete Description There are n different difficulty levels in Slay the Spire and Sora has to choose from level 1m each run. He will either succeed or fail each run: . If he succeeds on difficulty i, he's able to complete all lower levels; If he fails on difficulty i, he'll also fail on all higher levels However, Sora's patience is not unlimited: if he fails m runs and still has not found tho most diflicult level he's able to complete, he'll give up and never touch the game again Given n, m, assuming Sora makes optimal decisions on which difficulty to choose, what is the minimum number of games he will play (in the worst-case)? Sample Input 1 5 1 Output 1 Input 2 8 2 Output 2 4 Input3 1000 5 Output 3 Explanation In the first test case, there are 5 difficulty levels and Sora can't stand any failure Thus he has to go from the easiest level to the hardest in order, so that he immediately knows the answer once he fails. In the worst case, he has to try all 5 difficulty levels, therefore the answer is 5 In the sccond test case, there are 8 difficulty levels and Sora can fail twice. He should try level 4 first, then 1. If he fails, try levels 13 like in the first test case. 4 tries in total in the worst case. 2. If he succceds, try level 7 (a) If he succeeds, try level 8 and only 3 tries are needed b) If he fails, try levels 5~~6 in order. 4 tries in total in the worst case It can be proven that no better strategy exists in this case Constraints For all test cases, 1 m, n 1000000 Scoring To receive full credit, your algorithm must use dynamic programming, and correctly solve all our test cases in O(n3). If your algorithm can't solve n m- 500 in less than a second, your algorithm is not fast enough
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
