you give n x n grid represent field cherry cell possible integers0 mean cell pass through1 mean cell contain cherry pick pass or1 mean cell contain thorn block wayreturn maximum number cherry collect follow rule belowstarte position 0 0 reach n 1 n 1 move right valid path cell cell value 0 1After reach n 1 n 1 return 0 0 move leave valid path cellswhen pass path cell contain cherry pick cell cell 0if valid path 0 0 n 1 n 1 cherry collect Example 1input grid 011101111output 5explanation the player start 0 0 go right right reach 2 24 cherry pick single trip matrix 011001000then player went leave leave return home pick cherrythe total number cherry pick 5 maximum possibleExample 2input grid 111111111output 0 Constraintsn gridlengthn gridilength1 n 50gridij 1 0 1grid00 1gridn 1n 1 1