Shops
InterviewTime limit2sMemory limit256 MB
Pick cells with no shared side in an N by 5 profit grid to maximize the summed profit.
- Level
Medium5 of 10
- Topics
- Dynamic programming, Bit manipulation
- Solved
- No attempts yet
Problem
A fair site is an N by 5 grid. Each cell has a profit estimate. You may rent any set of cells, but no two rented cells may be side-adjacent (up, down, left, or right). Find the maximum total profit.
Input
The first line has T test cases. Each test case starts with N, followed by five lines of N nonnegative profits.
Output
For each test case, print the maximum total profit from a non-adjacent selection.