Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- const int rows = 5;
- const int cols = 8;
- int arr[rows][cols] = {
- { 0, 0, 0, 0, 1, 1, 0, 0, },
- { 1, 0, 0, 1, 1, 1, 0, 0, },
- { 1, 1, 0, 1, 0, 1, 1, 0, },
- { 0, 0, 0, 1, 1, 1, 1, 0, },
- { 0, 1, 1, 0, 0, 0, 0, 0, },
- };
- int fill(int [][cols], size_t, size_t);
- void print_array(int [][cols]);
- int main() {
- print_array(arr);
- system("pause");
- return 0;
- }
- void print_array(int arr[rows][cols]) {
- std::cout << "Default array: \n\n";
- for(size_t i = 0; i < rows; i++) {
- for(size_t j = 0; j < cols; j++)
- std::cout << " " << arr[i][j];
- std::cout << std::endl;
- }
- std::cout << "\n\nFilled array: \n\n";
- for(size_t i = 0; i < rows; i++) {
- for(size_t j = 0; j < cols; j++) {
- if(arr[i][j])
- fill(arr, i, j);
- std::cout << " " << arr[i][j];
- }
- std::cout << std::endl;
- }
- }
- int fill(int arr[rows][cols], size_t row, size_t col) {
- int count = 0;
- if (row < rows && arr[row][col]) {
- for (size_t i = col; i >= 0 && arr[row][i]; --i) {
- arr[row][i] = 2;
- count += fill(arr, row + 1, i) + 1; // count of max area covered
- }
- for (size_t i = col + 1; i < cols && arr[row][i]; ++i) {
- arr[row][i] = 2;
- count += fill(arr, row + 1, i) + 1; // count of max area covered
- }
- }
- return count;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement