Question: Python Program that reads a matrix MN which represents the map and prints the number of enemies ready to attack the kingdom: # 2 D
Python Program that reads a matrix MN which represents the map and prints the number of enemies ready to attack the kingdom:
#D array to store map of kingdom
arr
#Take input from user for size of matrix
MN intinput
#Taking values from user
for i in rangeM:
arr.appendintj for j in inputsplit
#D list to store true or false
#True represent current block is already visited
#False represent not visited
check
#initially all values set to false
for i in rangeM:
temp
for j in rangeN:
temp.appendFalseappends an element to end of the list
check.appendtemp
#variable to store the final sum
sum int
for i in rangeM:
for j in rangeN:
if arrij:
if i and checkij False:
checkij True
sum sumarrij
if j and checkij False:
checkij True
sum sumarrij
if jN and checkij False:
checkij True
sum sumarrij
if iM and checkij False:
checkij True
sum sumarrij
printsum
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
