Created
September 16, 2012 06:06
-
-
Save sreedharmb/3731221 to your computer and use it in GitHub Desktop.
You are given an integer s and an integer k. Find k positive integers a1, a2, ..., ak such that their sum is equal to s and their product is the maximal possible.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
int product(int s,int k) | |
{ | |
int temp=0; | |
int i,max; | |
if(k==1) | |
return s; | |
else | |
{ | |
for(i=1;i<s;i++) | |
{ | |
max=i*product(s-i,k-1); | |
if(max>temp) | |
temp=max; | |
} | |
return temp; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
good