- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
Physics
Chemistry
Biology
Mathematics
English
Economics
Psychology
Social Studies
Fashion Studies
Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Maximum value with the choice of either dividing or considering as it is in C++
In this tutorial, we will be discussing a program to find maximum value with the choice of either dividing or considering as it is.
For this we will be provided with an integer value. Our task is to find the maximum value with either by dividing the number into four parts recursively or choosing it as it is using the given function F(n) = max( (F(n/2) + F(n/3) + F(n/4) + F(n/5)), n).
Example
#include <bits/stdc++.h> using namespace std; //calculating the maximum result int findMaximum(int size) { int term[size + 1]; term[0] = 0; term[1] = 1; int i=2; while(i <= size) { term[i] = max(i, (term[i / 2] + term[i / 3] + term[i / 4] + term[i / 5])); i = i+1; } return term[size]; } int main() { int number = 37; cout << "Maximum possible sum: " << findMaximum(number)<< endl; return 0; }
Output
Maximum possible sum: 57
- Related Articles
- Maximum value with the choice of either dividing or considering as it is in C++ program
- 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++
- Maximum set bit sum in array without considering adjacent elements in C++
- Problem with division as output is either 0 or 1 when using ifthenelse condition in ABAP program
- Maximum sum after repeatedly dividing N by a divisor in C++
- How far it is justifiable to change the name of cities, considering the financial cost it involves?
- On adding phenolphthalein indicator to colourless solution, no change is observed. What is the nature of this solution?(a) Basic(b) Either acidic or basic(c) Either acidic or neutral(d) Either basic or neutral
- C++ Path with Maximum Average Value
- Maximum sum of distinct numbers with LCM as N in C++
- What is the maximum possible value of an integer in C# ?
- Find a value whose XOR with given number is maximum in C++
- When sunlight is concentrated on a piece of paper by a spherical mirror or lens, then a hole can be burnt in it. For doing this, the paper must be placed at he focus of:(a) either a convex mirror or convex lens (b) either a concave mirror or concave lens(c) either a concave mirror or convex lens (d) either a convex mirror or concave lens

Advertisements