Page 1 of 1

# 0 and 1 array Problem

Posted 05 July 2018 - 12:44 PM

The problem goes like this:
A house has n x m rooms (n and m natural numbers, n>=2 and m>=2) and is represented as a 2 dimensional Array with n rows(0 to n-1)and m columns(0 to m-1).The room at line i( 0 <= i <= n-1) and column j ( 0 <= j <= m-1 ) is identified by the pair of numbers (i,j).All rooms, with the exception of the ones situated on the first line(i=0) and the first colums (j=0),have a switch. Actuating the switch from the room (i,j) leads to the next result: in each of the rooms (i,j) , (i,j-1) , (i-1,j) , (i-1,j-1) ( the room with the switch, the one above, the one on the left and the one above to the left) if the light was on, it turns off , and if it was off it turns on.
Write

Is This A Good Question/Topic? 0

## Replies To: 0 and 1 array Problem

### #2 modi123_1 • • Suitor #2
•    Reputation: 15359
• Posts: 61,583
• Joined: 12-June 08

## Re: 0 and 1 array Problem

Posted 05 July 2018 - 12:48 PM

Is there a question?

## Re: 0 and 1 array Problem

Posted 05 July 2018 - 01:13 PM modi123_1, on 05 July 2018 - 12:48 PM, said:

Is there a question?

I don't know how to edit my post I made.I posted by mistake before I finished writing, here's the finished topic: https://www.dreaminc...1&#entry2369710
Here's how the problem goes:
A house has n x m rooms (n and m natural numbers, n>=2 and m>=2) and is represented as a 2 dimensional Array with n rows(0 to n-1)and m columns(0 to m-1).The room at line i( 0 <= i <= n-1) and column j ( 0 <= j <= m-1 ) is identified by the pair of numbers (i,j).All rooms, with the exception of the ones situated on the first line(i=0) and the first colums (j=0),have a switch. Actuating the switch from the room (i,j) leads to the next result: in each of the rooms (i,j) , (i,j-1) , (i-1,j) , (i-1,j-1) ( the room with the switch, the one above, the one on the left and the one above to the left) if the light was on, it turns off , and if it was off it turns on.
b)Write a function that takes as input a 2D array of 1s and 0s ,dimensions m and n as well as i and j representing a room (i,j) with a switch and outputs the array after turning the switch in the room (i,j).
c)Write a C++ function that takes as input a 2D array of 1s and 0s representing the state of the light in the room m, as well as the dimensions n ( n >=2) and m(m>=2) of the array.The function need to return '1' if there is a set of rooms such that actuating the switch in every room once leads to all lights from all the rooms turning off.Otherwise the function returns 0.You can use the function from B.To be used an algorithm as efficient as possible time-wise ; solutions that use backtracking will receive the most points.

I know how to do B the only problem is at c), I don't know how should I write using backtracking , otherwise I can think of other solutions.I'm not asking to write the code for me but just to give me an idea of how I should go about solving using backtracking.

This problem was translated by me from another language if you don't understand something you can ask me.

### #4 modi123_1 • • Suitor #2
•    Reputation: 15359
• Posts: 61,583
• Joined: 12-June 08

## Re: 0 and 1 array Problem

Posted 05 July 2018 - 02:40 PM

Closing duplicate topic.

Page 1 of 1

 .related ul { list-style-type: circle; font-size: 12px; font-weight: bold; } .related li { margin-bottom: 5px; background-position: left 7px !important; margin-left: -35px; } .related h2 { font-size: 18px; font-weight: bold; } .related a { color: blue; }