Heat Transfer

5

1 votes
Linear Algebra, Matrix - Multiplication, Medium, Mathematics
Problem

In this problem, we will consider a simple two-dimensional heat transfer model. We start by assuming that we have some rectangular room of dimension n×m  which we divide into a grid. Let's call the cell on the ith row and the jth column as (i,j). Inside the grid, we will randomly scatter a handful of heaters. The initial temperature of the cell(i,j) is denoted by T0ij which is 1 units if there is a heater, 0 units otherwise. At every step in time, there is some heat flow between a cell and its neighbours. The update equation of temperature of cells (i,j) at time step zz+1 looks as

Tz+1ij=Tzij+x,yneigboursk×(TzxyTzij)

In the equation for updating the cell’s temperature, the constant k  simply represents the rate at which heat flows. The neighbors of cell (i,j) are the cells which shares a side with cell (i,j) i.e we consider only four neighbors (top, bottom, left, right).

Given the initial temperature of cells in the grid, Can you tell the temperature of cells after x time steps. Since the temperature of cells can be very large output the temperature modulo 109+7.

Constraints:

  • 2n,m10
  • 1k10
  • 1x109
  • 0T0ij1

Input Format:

The first line contains four space-separated integers n,m,k, and x.

Next n lines contain m integers jth interger in ith line is T0ij. The initial temperature of cell (i,j).

Output Format:

Output n  lines, each containing m integer. jth interger in ith line denotes the temperature of cell (i,j) after x time steps.

Time Limit: 2
Memory Limit: 256
Source Limit:
Explanation

enter image description here

Note: The above figure explains the sample test case.

Editor Image

?