 
  Data Structure Data Structure
 Networking Networking
 RDBMS RDBMS
 Operating System Operating System
 Java Java
 MS Excel MS Excel
 iOS iOS
 HTML HTML
 CSS CSS
 Android Android
 Python Python
 C Programming C Programming
 C++ C++
 C# C#
 MongoDB MongoDB
 MySQL MySQL
 Javascript Javascript
 PHP 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
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
Advertisements
 