Question: [Python] Domino Mirko received an N N table for his birthday, where a non-negative integer is written in each field of the table. Unfortunately, the

[Python] Domino

Mirko received an N N table for his birthday, where a non-negative integer is written in each field of the table. Unfortunately, the written numbers are too large for Mirkos taste, so he will place K dominoes on top of the table that will cover the fields that are too large. More precisely, Mirko places the dominoes according to the following rules:

- each domino covers two fields of the table that are adjacent in a row or in a column,

- the dominoes do not overlap (but can touch),

- the sum of all visible (uncovered) fields needs to be as small as possible.

It is your task to determine the required minimal sum of visible fields. The test data will be such that it will always be possible to place K dominoes without overlapping.

Input

The first line of input contains the integers [Python] Domino Mirko received an N N table for his birthday, where , the dimensions of the table, and a non-negative integer is written in each field of the table. Unfortunately, , the number of dominoes. Each of the following N lines contains N integers from the interval the written numbers are too large for Mirkos taste, so he will. These N N numbers describe Mirkos table.

Output

The first and only line of output must contain the minimal sum of visible fields after covering the table with dominoes.

place K dominoes on top of the table that will cover the

N (1 S N S 2000) N (1 S N S 2000)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!