Recursively break a number in 3 parts to get maximum sum | A simple recursive C ++ program to find maximum sum by recursively breaking a number in 3 parts . ; Function to find the maximum sum ; base conditions ; recursively break the number and return what maximum you can get ; Driver program to run the case
#include <bits/stdc++.h> NEW_LINE using namespace std ; int breakSum ( int n ) { if ( n == 0 n == 1 ) return n ; return max ( ( breakSum ( n / 2 ) + breakSum ( n / 3 ) + breakSum ( n / 4 ) ) , n ) ; } int main ( ) { int n = 12 ; cout << breakSum ( n ) ; return 0 ; }