Laser Tanks
Practice
2.4 (13 votes)
2 D array
Algorithms
Approved
Dynamic programming
Dynamic programming
Medium
Problem
94% Success 2417 Attempts 30 Points 1s Time Limit 256MB Memory 1024 KB Max Code

Several tanks have been arranged in N x N grid with each cell containing exactly one tank. These tanks are laser tanks - they shoot continuous laser beams instead of bullets. Each tank can shoot in two directions - upwards and rightwards, but in only one direction at a time. Tank located in ith row and jth column can shoot in upwards direction with power Vij and in rightwards direction with power Hij. However, if any horizontal laser beam meets vertical laser beam, they creates a big explosion. That's why, you have to assign directions to tanks in such a way that no explosion happens and maximum firepower is achieved. Firepower is defined as total power of all laser beams which have been shot by the tanks.

INPUT:
First line of input will consists of integer N denoting size of the grid. Next N lines will contain N integers, jth integer in the ith line will contain Hij. Similarly, Next N lines will contain N integers denoting matrix Vij

OUTPUT:
Output the maximum total firepower that can be achieved.

CONSTRAINTS:
1 ≤ N ≤ 1000
1 ≤ Vij ≤ 105
1 ≤ Hij ≤ 105

Please login to use the editor

You need to be logged in to access the code editor

Loading...

Please wait while we load the editor

Loading...
Results
Custom Input
Run your code to see the output
Submissions
Please login to view your submissions
Similar Problems
Points:30
9 votes
Tags:
Dynamic ProgrammingAlgorithms2D dynamic programmingData Structures
Points:30
24 votes
Tags:
AlgorithmsDynamic ProgrammingDynamic programming
Points:30
19 votes
Tags:
AlgorithmsDynamic Programming2D dynamic programming