FARIDA - Princess Farida

Once upon time there was a cute princess called Farida living in a castle with her father, mother and uncle. On the way to the castle there lived many monsters. Each one of them had some gold coins. Although they are monsters they will not hurt. Instead they will give you the gold coins, but if and only if you didn't take any coins from the monster directly before the current one. To marry princess Farida you have to pass all the monsters and collect as many coins as possible. Given the number of gold coins each monster has, calculate the maximum number of coins you can collect on your way to the castle.


The first line of input contains the number of test cases. Each test case starts with a number N, the number of monsters, 0 <= N <= 10^4. The next line will have N numbers, number of coins each monster has, 0 <= The number of coins with each monster <= 10^9. Monsters described in the order they are encountered on the way to the castle.


For each test case print “Case C: X” without quotes. C is the case number, starting with 1. X is the maximum number of coins you can collect.


1 2 3 4 5

Case 1: 9
Case 2: 10

hide comments
phoemur: 2018-09-12 02:09:26

@mayank_75 While taking only even or odd indices will ensure we visit the maximum number of monsters, it doesn’t guarantee maximum value gathered.

This is the same as the classic DP problem House Robber.
Explanation here: https://codesignal.com/houserobber-solution/

mayank_75: 2018-09-03 15:47:35

can somebody tell me how is this a dp problem, why cant we use simply array and count the sum of odd indices and even indices and then take the max of the two sums?
Am i missing something, please let me know?
Thanks in advance!

Malay Kumar Singh: 2018-08-02 16:49:21

My GO code is TLE no matter what I do, any suggestions?

jason_chatz: 2018-08-02 14:12:34

Remember long (or even long long to be safe).

badboy_1496: 2018-07-19 12:06:59

ac in one go!!!

abdelhameedddd: 2018-07-09 21:21:16


wolv_dhoni: 2018-07-06 23:43:21

Last edit: 2018-07-06 23:44:37
ash_maurya: 2018-06-23 16:43:21

Nice DP problem. Number of monsters could be zero, costed me two WAs.

kaush1: 2018-06-20 14:02:29

Remember to print Case number also. I forgot to print case...

itachi_2016: 2018-06-14 13:24:06

Take care for n = 0, my 50th :p

Last edit: 2018-06-16 14:32:14

Added by:hossamyosef
Time limit:1.237s
Source limit:50000B
Memory limit:1536MB
Cluster: Cube (Intel G860)
Languages:All except: ASM64
Resource:FCIS/ASU Local Contest 2013