Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <fstream>
- using namespace std;
- const int COLOR[3] = {1, 2, 3}; //Red, Blue, Purple
- int Desk[6][4] = {0};
- ofstream out("DRAFT.OUT");
- void print(int row, int col) {
- int R = 0, B = 0, P = 0;
- for (int i = 0; i < row; ++i) {
- for (int j = 0; j < col; ++j) {
- out << Desk[i][j] << " ";
- if (Desk[i][j] == COLOR[0]) ++R; //Red
- else if (Desk[i][j] == COLOR[1]) ++B; //Blue
- else ++P; //Purple
- }
- out << endl;
- }
- out << "Red: " << R << " Blue: " << B << " Purple: " << P << endl;
- }
- bool canPlace(int color, int row, int col) {
- return (row-1 > -1 && Desk[row-1][col] != color)
- && (col-1 > -1 && Desk[row][col-1] != color);
- }
- void solve(int row, int col, int p = 0) {
- if (p >= row * col) {
- print(row, col);
- return;
- }
- int r = p / col, c = p % col;
- for (int i = 0; i < 3; ++i) {
- if ( canPlace(COLOR[i], r, c) ) {
- Desk[r][c] = COLOR[i];
- solve(row, col, p + 1);
- Desk[r][c] = 0;
- }
- }
- }
- int main (void) {
- solve(6, 4);
- out.close();
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement