943,952 Members | Top Members by Rank

Ad:
Nov 29th, 2007
0

Algorithm HELP!

Expand Post »
Hi guys. Im a student and i have a problem in finding the right procedure to solve my problem. Giving a set of numbers that will find their combination for a given value. For example 1st digit will be the size and the 2nd digit will be the qty.:

Size qty
10 10
20 10
30 10
40 10
50 10
60 10
70 10
80 10
90 10
100 10

the problem will be, I’ll find the 1 to 5 combinations to have a sum of 100:
the answers will be like the following:


100 10
90+10 10
80+20 10
70+30 10
40+60 10
50+50 5

the answers is only 1 and 2 combinations. I would like to create a procedure that will compute up to 5 combinations and will check the qty is still available for combining into another size. the problem is my function becomes very slow when im trying to manipulate it using string handling functions. Any input that will enlighten my mind will be a great help. Thanks in advance.
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
student101110 is offline Offline
6 posts
since Nov 2007
Nov 29th, 2007
0

Re: Algorithm HELP!

Please specify the total number of sequence (ex.. 1 to totalnumberofsequence) if the total number of sequence is base on the input try this systax

Dim input as integer
dim algo as integer
dim cnt as integer
dim combo as integer

'no of sequence
algo = 0
for cnt = 1 to input
algo = algo + input
? algo, input
next cnt

'finding the combination
cnt = 0
combo = algo
algo = algo - input
while combo = algo
cnt = cnt + 1
combo = (algo + input)
input = input + input

loop

' cnt is the total number of combination
Reputation Points: 10
Solved Threads: 0
Light Poster
locsin is offline Offline
47 posts
since Aug 2007
Dec 2nd, 2007
0

Re: Algorithm HELP!

thanks for the input locsin. i already created a function that will loop (1 to 5 comb) to combine the given set of numbers. the problem is im having trouble with getting the difference of the qty. for example:

---------------------------------------
combination requirement= 400

size 100+90+80+70+60

qty respectively 10,9,8,7,6

ANS:

6 set for 100+90+80+70+60

qty respectively 4,3,2,1,0

---------------------------------------

this sample is easy to compute coz of theres no redundant size have been combined. the next example will be a little bit of complicated:

----------------------------------------
combination requirement= 400

size 100+100+90+80+30

qty respectively 10,10,11,12,13

ANS:

5 sets for 100+100+90+80+30

qty respectively 0,0,6,7,8
------------------------------------------

the problem is, am having trouble with getting the difference of the qty. for now, im using a string handling function for computation of combinations but reducing the qty is my main problem using that function( ex. sorting the qty and determining the lowest qty to be the set size). can someone suggest an idea that will help me to solve my problem? thanks all.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
student101110 is offline Offline
6 posts
since Nov 2007
Dec 2nd, 2007
0

Re: Algorithm HELP!

btw, im using a two dimensional array to manipulate my string. is there any function in vb that i can store my var and automaticaly sort them?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
student101110 is offline Offline
6 posts
since Nov 2007
Dec 6th, 2007
0

Re: Algorithm HELP!

up
Reputation Points: 10
Solved Threads: 0
Newbie Poster
student101110 is offline Offline
6 posts
since Nov 2007

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in Visual Basic 4 / 5 / 6 Forum Timeline: Media Control Interface (MCI) vb script help
Next Thread in Visual Basic 4 / 5 / 6 Forum Timeline: help me out...





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC