Editing
2016 Jan Platinum Problem 3 Lights Out
(section)
Jump to navigation
Jump to search
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
== Solution == The solution to this problem involves two main steps: First, precomputing the shortest path between each pair of switches using the Floyd-Warshall algorithm. Second, using dynamic programming to find the minimum number of steps. In the precomputing step, because the cows can be in either of two states (on or off), we calculate the shortest path twice: once when the switch is on and once when it's off. We initialize the 3D array for this step such that the distance between each switch and itself is 0, and the distance between all other switches is infinity. Then we update the array based on the given connections, and finally we run the Floyd-Warshall algorithm to calculate the shortest paths. In the dynamic programming step, we define dp[i][mask] as the minimum number of steps needed to turn off all the switches from switch i when the switches indicated by the mask are still on. We initialize this dp array to infinity, and then update it iteratively. We iterate over each mask in increasing order of the number of switches that are on. Then for each switch that is still on, we calculate the minimum number of steps to turn off all the switches by visiting switch i last, considering all possible previous switches we could have visited. This approach ensures that we consider all possibilities and find the minimum number of steps that Bessie needs to take.
Summary:
Please note that all contributions to Wiki may be edited, altered, or removed by other contributors. If you do not want your writing to be edited mercilessly, then do not submit it here.
You are also promising us that you wrote this yourself, or copied it from a public domain or similar free resource (see
My wiki:Copyrights
for details).
Do not submit copyrighted work without permission!
Cancel
Editing help
(opens in new window)
Navigation menu
Personal tools
Not logged in
Talk
Contributions
Create account
Log in
Namespaces
Page
Discussion
English
Views
Read
Edit
View history
More
Search
Navigation
Main page
Recent changes
Random page
Help about MediaWiki
Tools
What links here
Related changes
Special pages
Page information