Answered step by step
Verified Expert Solution
Question
1 Approved Answer
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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started