You are on page 1of 2

CRAZZZY THIEF

The king of thieves Kukki has been recently released from the prison. He has a very peculiar habit of
executing his plans. Firstly he acquires the map of the place and then divide it into levels and further
sub-dividing each level thus creating a grid structure. But since he spent so many years in prison he is
out of his mind and he needs your help. Being his accomplice u need to execute the plan so as to steal
maximum profit. You will be given the overview of the map as a array of string. Each character of a
cell gives you the number of diamonds present at that location. You should start at the top-left corner
of the map ( Element (0,0) ) . On a current state you should move in accordance of the following
rules :

1. On the first traversal you should start from the upper left corner of the matrix. You can move
down or right one cell at a time ( no diagonal moves ). You need to reach at the bottom right
corner.
2. After reaching at the bottom right corner you need to again reach at the starting location
(upper left cell) by moving at each step one cell left or one cell up.
3. On arriving at this upper –left cell, you are required to go again back to the bottom –right cell.
(Don’t get mad at me.. its kukki who is responsible for this , after all this is his plan ). Now
kukki leaves the place with all the diamonds collected.

When you reach a location u collect all the diamonds placed at the cell. So now help your best
friend Kukki to collect maximum number of diamonds.

Constraints:

 Number of levels will range between 2 to 60.


 Each level can contain 2 to 60 cells.
 All levels will contain same number of cells.
 Each cell contains a digit ‘0’ to ‘9’.
 Element (0,0)= 0 (no diamonds).

You are required to write a function maxProfit ( Prototype give below ) :

int maxProfit(char map[][62], int level)

or, int maxProfit(char (*map)[62], int level)

(Each string will be NULL terminated that is ‘\0’ , so can find number of columns. You can change
prototype slightly if u need but u need to mention it with a support file explaining your approach).

which return the maximum number of diamonds collected.


Examples:

(Spaces are for your clear understanding.)

1) 0 9 0 0
0 9 9 8
0 8 9 9
9 0 0 9

Return value: 79
2) 0 2
1 2
1 2

Return Value: 8

3) 0 3 3 3 1 1 1 1 1 1
1 3 0 0 0 0 0 0 0 0
1 3 3 0 9 9 9 9 9 0
1 0 3 0 9 9 9 9 9 0
1 0 3 0 9 9 9 9 9 0
1 0 1 0 9 9 9 9 9 0
1 0 1 1 0 0 0 0 0 0
1 1 1 1 1 1 1 1 1 1

Return Value: 195

For any ambiguity noticed or further clarification please mail at:

codepool.literati2k10@gmail.com

Or Contact:

Arpit Rusia Rohit Wali


arpitrusia@gmail.com rohitwalz.nitk@gmail.com
+91 9034491224 +91 9896741185

You might also like