Coin Row
InterviewTime limit1sMemory limit128 MB
Given rows of coin values, pick non-adjacent coins to maximize the total collected in each row.
- Level
Easy3 of 10
- Topics
- Dynamic programming, Array
- Solved
- No attempts yet
Problem
A row of coins has positive integer values (not necessarily distinct). Select coins so that the total value collected is as large as possible, subject to the constraint that no two adjacent coins may be selected.
Input
The first line contains a positive integer , the number of coin rows that follow. Each of the next lines describes one coin row as a list of positive integers separated by one or more spaces. A row contains at most 20 coins.
Output
For each coin row, print on its own line the maximum total value you can collect subject to the constraint that no two adjacent coins are selected. Print each answer as a plain positive integer with no extra formatting.