Reply
 
LinkBack Thread Tools Display Modes
  #1 (permalink)  
Old 11-27-2009, 03:32 PM
Member
 
Join Date: Nov 2009
Posts: 1
Rep Power: 0
gmnnn is on a distinguished road
Default 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(a-1,b-1)+P(a-b,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.
Bookmark Post in Technorati
Reply With Quote
  #2 (permalink)  
Old 12-06-2009, 05:22 PM
Member
 
Join Date: Dec 2009
Posts: 16
Rep Power: 0
wtd_nielsen is on a distinguished road
Default
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(a-1,b-1)+duo(a-b,b);
}
return result;
}

but i dont think it is correct?

Last edited by wtd_nielsen; 12-06-2009 at 05:28 PM.
Bookmark Post in Technorati
Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Similar Threads
Thread Thread Starter Forum Replies Last Post
Recursion depth in java poulius New To Java 17 01-11-2009 02:38 PM
java recursion help khdani New To Java 4 12-29-2008 09:56 PM
Recursion in Java .. Java01 New To Java 6 10-24-2008 12:42 PM
i could not get the recursion in java sivasayanth New To Java 3 04-23-2008 09:08 AM
Recursion in java lenny Advanced Java 1 08-07-2007 07:23 AM


All times are GMT +2. The time now is 02:19 PM.



VBulletin, Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Content Relevant URLs by vBSEO ©2009, Crawlability, Inc.
Copyright ©2006 - 2007, www.java-forums.org