- Trending Categories
- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP

- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who

In this problem, we are given two dimensional arrays mat[n][m]. Our task is to find the number of endless points in the matrix.

Any point of the matrix is said to be endless if its next elements are 1. i.e.

mat[i][j] is endless when mat[i+1][j] … mat[n][j] and mat[i][j+1] … mat[i][m] are 1.

**Let’s take an example to understand the problem,**

mat[][] = {0, 0} {1, 1}

2

Element mat[0][1] and mat[1][1] are endless.

A simple solution to the problem is by iterating all elements of the matrix. And for each element check if the current element is endless or not. If yes, increase count. Return the count after checking all elements of the array.

To solve the problem, we will use dynamic programming to check if elements are endless or not. For it to be endless all elements of its row and columns after it need to be 1.

So, we will use two DP matrices to count endless next row and endless next columns for each index. And the check of each position, if the position has the next endless row and column. Then return the count of endless elements.

**Program to illustrate the working of our solution,**

#include <iostream> #include <math.h> using namespace std; const int monthDays[12] = { 31, 59, 90, 120, 151, 181, 212, 243, 273, 304, 334, 365 }; int countLeapYearDays(int d[]){ int years = d[2]; if (d[1] <= 2) years--; return ( (years / 4) - (years / 100) + (years / 400) ); } int countNoOfDays(int date1[], int date2[]){ long int dayCount1 = (date1[2] * 365); dayCount1 += monthDays[date1[1]]; dayCount1 += date1[0]; dayCount1 += countLeapYearDays(date1); long int dayCount2 = (date2[2] * 365); dayCount2 += monthDays[date2[1]]; dayCount2 += date2[0]; dayCount2 += countLeapYearDays(date2); return ( abs(dayCount1 - dayCount2) ); } int main(){ int date1[3] = {13, 3, 2021}; int date2[3] = {24, 5, 2023}; cout<<"The number of days between two dates is "<<countNoOfDays(date1, date2); return 0; }

The number of days between two dates is 802

- Related Questions & Answers
- Number of Integral Points between Two Points in C++
- C++ Program to Find Number of Articulation points in a Graph
- Find the Number of Quadrilaterals Possible from the Given Points using C++
- Find Corners of Rectangle using mid points in C++
- Number of ordered points pair satisfying line equation in C++
- Prime points (Points that split a number into two primes) in C++
- Printing the correct number of decimal points with cout in C++
- Find the Number of Triangles Formed from a Set of Points on Three Lines using C++\n
- C++ Program to Find Closest Pair of Points in an Array
- Minimum number of points to be removed to get remaining points on one side of axis using C++.
- Maximum number of fixed points using at most 1 swaps in C++
- Maximum number of segments that can contain the given points in C++
- Find Simple Closed Path for a given set of points in C++
- Find K Closest Points to the Origin in C++
- Print all combinations of points that can compose a given number in C++

Advertisements