Maximum number of ones in a N * N matrix with given constraints | C ++ program to get Maximum Number of ones in a matrix with given constraints ; Function that returns the maximum number of ones ; Minimum number of zeroes ; Totol cells = square of the size of the matrices ; Initialising the answer ; Driver code ; Initialising the variables
#include <bits/stdc++.h> NEW_LINE using namespace std ; int getMaxOnes ( int n , int x ) { int zeroes = ( n / x ) ; zeroes = zeroes * zeroes ; int total = n * n ; int ans = total - zeroes ; return ans ; } int main ( ) { int n = 5 ; int x = 2 ; cout << getMaxOnes ( n , x ) ; return 0 ; }