- Related Questions & Answers
- Maximum value with the choice of either dividing or considering as it is 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
- What is the maximum possible value of an integer in C# ?
- How far it is justifiable to change the name of cities, considering the financial cost it involves?
- What is the maximum value of float in Python?
- Program to find the minimum (or maximum) element of an array in C++
- Maximum sum of distinct numbers with LCM as N in C++
- Print pair with maximum AND value in an array in C Program.
- Java Program to get maximum value with Comparator
- C++ Program to Find Maximum Value of any Algebraic Expression
- Is it possible to use MongoDB field value as pattern in $regex?
- Maximum sum of lengths of non-overlapping subarrays with k as the max element in C++
- A permutation where each element indicates either number of elements before or after it?
- Maximum of Absolute Value Expression in C++

- 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 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).

#include <bits/stdc++.h> using namespace std; //calculating the maximum result int maxDP(int n) { int res[n + 1]; res[0] = 0; res[1] = 1; for (int i = 2; i <= n; i++) res[i] = max(i, (res[i / 2] + res[i / 3] + res[i / 4] + res[i / 5])); return res[n]; } int main() { int n = 60; cout << "MaxSum =" << maxDP(n); return 0; }

MaxSum =106

Advertisements