Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Computer Science C++ questionPlease do not copy and paste the answers that already exist, because those are not correct, thank you 2. Program (a) You
Computer Science C++ questionPlease do not copy and paste the answers that already exist, because those are not correct, thank you
2. Program (a) You need to implement your algorithms in C. (b) Your program reads a test case from "input.txt". (c) "input.txt" only contains the values for each target, one value on each line. (d) Your program outputs the resulting score on the screen and the cor- responding shooting sequence to "output.txt", one index of a target on each line. Shooting Competition Philoctetes is a sharp shooter. One day he is invited by a shooting competition. In the competition, each shooter is given an array of n targets. Every target has a value, a positive integer. If one target t is shot, the shooter's scores will be increased by 1 X 0 X 03 where w is the value on the target I, uy is the value on t's left neighbor, and us is the value on t's right neighbor. You need to design a greed algorithm and a dynamic programming algorithm to find an shooting order to maximize the score earned by Philoctetes under the following assumptions. 1. Philoctetes never misses any target. 2. Shooters know the value on every target before shooting. 3. Each target has only two neighbors, left and right. 4. If one target is shot, its left and right neighbors will be neighbors after- wards. 5. Pretend that the first target has an artificial left neighbor - target 0. Philoctetes cannot shoot target o, but the target has value 1 and will be counted in the score calculation. 6. Similarly, the right nieghbor of the last target is also an artificial target 11 + 1 of value 1, which cannot be shot. Requirements 1. Algorithms (a) The greedy algorithm runs in On log n) time and uses (1) space. The greedy algorithm is not required to always find the maximum score. (1) The dynamic programming runs in O(n) time and uses O(n) space. It always gives the maximum score. Example Suppose Philocletes is given 4 targes of values 2, 1, 4,3 (see input.example.txt"), the maximum score is 41 because Iteration Target index Score Values of the remaining targets 1 Target 2 (valued 1) 0+2x1x4 2, 4,3 2 Target 3 (valued 4) 8 + 2 x 4 X 3 3 Target I valued 2) 32 +1 X2 X3 3 Target 4 vnlued 3) 38 +1x3x1 Empty The shooting sequence 2, 3, 1, 4 is in "output.example.txt". Greedy_Algorith... 2. Program (a) You need to implement your algorithms in C. (b) Your program reads a test case from "input.txt". (c) "input.txt" only contains the values for each target, one value on each line. (d) Your program outputs the resulting score on the screen and the cor- responding shooting sequence to "output.txt", one index of a target on each line. Shooting Competition Philoctetes is a sharp shooter. One day he is invited by a shooting competition. In the competition, each shooter is given an array of n targets. Every target has a value, a positive integer. If one target t is shot, the shooter's scores will be increased by 1 X 0 X 03 where w is the value on the target I, uy is the value on t's left neighbor, and us is the value on t's right neighbor. You need to design a greed algorithm and a dynamic programming algorithm to find an shooting order to maximize the score earned by Philoctetes under the following assumptions. 1. Philoctetes never misses any target. 2. Shooters know the value on every target before shooting. 3. Each target has only two neighbors, left and right. 4. If one target is shot, its left and right neighbors will be neighbors after- wards. 5. Pretend that the first target has an artificial left neighbor - target 0. Philoctetes cannot shoot target o, but the target has value 1 and will be counted in the score calculation. 6. Similarly, the right nieghbor of the last target is also an artificial target 11 + 1 of value 1, which cannot be shot. Requirements 1. Algorithms (a) The greedy algorithm runs in On log n) time and uses (1) space. The greedy algorithm is not required to always find the maximum score. (1) The dynamic programming runs in O(n) time and uses O(n) space. It always gives the maximum score. Example Suppose Philocletes is given 4 targes of values 2, 1, 4,3 (see input.example.txt"), the maximum score is 41 because Iteration Target index Score Values of the remaining targets 1 Target 2 (valued 1) 0+2x1x4 2, 4,3 2 Target 3 (valued 4) 8 + 2 x 4 X 3 3 Target I valued 2) 32 +1 X2 X3 3 Target 4 vnlued 3) 38 +1x3x1 Empty The shooting sequence 2, 3, 1, 4 is in "output.example.txt". Greedy_Algorith
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started