Complete the 8 queens 2 dimensional array

Assignment Help C/C++ Programming
Reference no: EM13167720

Complete the 8 queens 2 dimensional array program with backtracking. please change the below program using backtracking  and please run before posting it . the program suppose to print 92 solution . amd also comment before each line to better understand.


#include <cmath> #include <iostream> using namespace std; bool ok(int board[][8]){ for(int c = 7; c > 0; c--){ int r = 0; while(board[r][c] != 1 ){ r++; } for(int i = 1; i <= c; i++){ if(board[r][c-i] == 1) return false; else if (board[r-i][c-i] == 1) return false; else if (board[r+i][c-i] == 1) return false; } } return true; } void print(int board[][8], int count){ cout << count << endl; for(int i = 0; i < 8; i++){ for(int j = 0; j < 8; j++){ cout << board[i][j]; } cout << endl; } } int main (){ int board[8][8]; for ( int i = 0; i < 8; i++ ) for ( int j = 0; j < 8; j++ ) board[i][j] = 0; int count = 0; for(int i0 = 0; i0 < 8; i0++) for(int i1=0; i1 < 8; i1++) for(int i2 = 0; i2 < 8; i2++) for(int i3 = 0; i3 < 8; i3++) for(int i4 = 0; i4 < 8; i4++) for(int i5 = 0; i5 < 8; i5++) for(int i6 = 0; i6 < 8; i6++) for(int i7 = 0; i7 < 8; i7++){ board[i0][0]=1; board[i1][1]=1; board[i2][2]=1; board[i3][3]=1; board[i4][4]=1; board[i5][5]=1; board[i6][6]=1; board[i7][7]=1; if(ok(board))print(board, ++count); board[i0][0]=0; board[i1][1]=0; board[i2][2]=0; board[i3][3]=0; board[i4][4]=0; board[i5][5]=0; board[i6][6]=0; board[i7][7]=0; } return 0; }

Reference no: EM13167720

Questions Cloud

Binary relation on s for reflexivity, symmetry, antisymmetry : Let S={1,2,3,4,5,6,7,8}. Test the following binary relation on S for reflexivity, symmetry, antisymmetry, and transitivity
Find the domain for each of two rational expressions : Find your two rational expressions in the list below based on the first letter of your first name and explain in your own words what the meaning of domain is. Also, explain why a denominator cannot be zero.
Program consists of a 200-instruction : A given program consists of a 200-instruction loop that is executed 50 times. If it takes 20,000 cycles to execute the program on a given system, what are that system's cycle per instruction
The single processor system : Suppose further that a single processor system can solve the problem in 106 seconds (about 11.6 days). So, on average, the single processor system
Complete the 8 queens 2 dimensional array : Complete the 8 queens 2 dimensional array program with backtracking. please change the below program using backtracking  and please run before posting it . the program suppose to print 92 solution . amd also comment before each line to better unde..
Horizontal distance of the tire valve : Define a function that gives the horizontal distance of the tire valve to the right of the tire's vertical diameter ...
Design and draw the state diagram : Design and draw the state diagram (graph-representation) of a deterministic finite-state automata that recognizes the language generated by the grammar
T an array using insertion sort and track the number of swap : How to sort an array using insertion sort and track teh number of swaps during the sorting
Quality of building management : What role does the quality of building management and operations play vis-a-vis a strictly technological approach to energy efficiency? Why?

Reviews

Write a Review

C/C++ Programming Questions & Answers

  Create program that uses functions and reference parameters

Create program that uses functions and reference parameters, and asks user for the outside temperature.

  Write a program using vectors and iterators

Write a program using vectors and iterators that allows a user to maintain a personal list of DVD titles

  Write the code required to analyse and display the data

Calculate and store the average for each row and column. Determine and store the values for the Average Map.

  Write a webservices application

Write a webservices application that does a simple four function calculator

  Iimplement a client-server of the game

Iimplement a client-server version of the rock-paper-scissors-lizard-Spock game.

  Model-view-controller

Explain Model-View-Controller paradigm

  Design a nested program

How many levels of nesting are there in this design?

  Convert celsius temperatures to fahrenheit temperatures

Write a C++ program that converts Celsius Temperatures to Fahrenheit Temperatures.

  Evaluate and output the value in the given base

Write C program that will input two values from the user that are a Value and a Base with which you will evaluate and output the Value in the given Base.

  Design a base class shape with virtual functions

Design a base class shape with virtual functions

  Implementation of classes

Implementation of classes Chart and BarChart. Class barChart chould display a simple textual representation of the data

  Technical paper: memory management

Technical Paper: Memory Management, The intent of this paper is to provide you with an in depth knowledge of how memory is used in executing, your programs and its critical support for applications.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd