Results 1 to 2 of 2
Thread: Java Recursion Problem
 11272009, 02:32 PM #1Member
 Join Date
 Nov 2009
 Posts
 1
 Rep Power
 0
Java Recursion Problem
Hey guys,
I'm gonna write that code:
There is the duo P(a,b) and my code finds how many ways are there to represent "a" as sum of "b" number
Example: P(4,2)
4=3+1 ve 2+2. If there was P(4,3), it would be only 1+1+2 etc.
We have those infos:
for P(a,b), if a=b, there is 1 way
if a<b, there is no way and
for b=2, there are "the floor of a/b" way. Example: for P(7,2), (7/2)=(3,5)=3 different ways.
In addition, we know that P(a,b) = P(a1,b1)+P(ab,b). The purpose is to reduce given a,b duo to duos which we know, by applying the last operation that i wrote. Example:
P(9,4) = P(8,3) + P(5,4)
= P(7,2) + P(5,3) + P(4,3) + P(1,4)
We know that how many ways are there to represent P(7,2) duo (3) and P(1,4) duo can be written as 0 different ways. We are trying to find the solution by applying same operation to P(5,3) and P(4,3) duos. But i couldn't write that code, show me a way please.
 12062009, 04:22 PM #2Member
 Join Date
 Dec 2009
 Posts
 24
 Rep Power
 0
have you written any code that we could have a look at?
*edit:
hmm since its been a while since he asked the question, I will try with an solution:
public static int duo(int a, int b)
{
int result = 0;
if(a==b)
return 1;
else if(b==2)
{
return a/b;
}
else if(a>b)
{
result = duo(a1,b1)+duo(ab,b);
}
return result;
}
but i dont think it is correct?Last edited by wtd_nielsen; 12062009 at 04:28 PM.
Similar Threads

Recursion depth in java
By poulius in forum New To JavaReplies: 17Last Post: 01112009, 01:38 PM 
java recursion help
By khdani in forum New To JavaReplies: 4Last Post: 12292008, 08:56 PM 
Recursion in Java ..
By Java01 in forum New To JavaReplies: 6Last Post: 10242008, 11:42 AM 
i could not get the recursion in java
By sivasayanth in forum New To JavaReplies: 3Last Post: 04232008, 08:08 AM 
Recursion in java
By lenny in forum Advanced JavaReplies: 1Last Post: 08072007, 06:23 AM
Bookmarks