- 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 a number N. Our task is to create a program to find to Maximum value with the choice of either dividing or considering as it is in C++.

To find the maximum, we can consider any two values, either by take the value as it is or we could get the maximum value by dividing.The value could be extracted as **F(N/2) + F(N/3) + F(N/4) +
F(N/5)**.

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

**Input**:N = 8

**Output**:9

F(8) =F(8/2) + F(8/3) + F(8/4) + F(8/5) = F(4) + F(2) + F(2) + F(1) = 4 + 2 + 2 + 1 = 9

The idea is simply to call the same function multiple times for the value of division. For this we have used the concept dynamic programming and created an array to solve the values of F(i) from 0 to N, for recusing them for finding the solution.

#include <iostream> using namespace std; int calcMaximumValue(int N) { int F[N + 1]; int divVal = 0; F[0] = 0; F[1] = 1; for (int i = 2; i <= N; i++) { divVal = ( F[i / 2] + F[i / 3] + F[i / 4] + F[i / 5] ); if(divVal > i) F[i] = divVal; else F[i] = i; } return F[N]; } int main() { int N = 8; cout<<"Maximum value with the choice of either dividing or considering as it is = "<<calcMaximumValue(N); return 0; }

Maximum value with the choice of either dividing or considering as it is = 9

- Related Questions & Answers
- Maximum value with the choice of either dividing or considering as it is in C++
- Maximum length subarray with difference between adjacent elements as either 0 or 1 in C++
- Maximum length subsequence with difference between adjacent elements as either 0 or 1 in C++
- Maximum length subsequence with difference between adjacent elements as either 0 or 1 | Set 2 in C++
- Maximum determinant of a matrix with every values either 0 or n in C++
- Problem with division as output is either 0 or 1 when using ifthenelse condition in ABAP program
- How far it is justifiable to change the name of cities, considering the financial cost it involves?
- What is the maximum possible value of an integer in C# ?
- Delete leaf nodes with value as x in C++ Program
- A permutation where each element indicates either number of elements before or after it?
- Python Program – Print the count of either peaks or valleys from a list
- What is the maximum value of float in Python?
- Maximum sum after repeatedly dividing N by a divisor in C++
- Maximum sum of distinct numbers with LCM as N in C++
- C program to find out the maximum value of AND, OR, and XOR operations that are less than a given value

Advertisements