944,038 Members | Top Members by Rank

Ad:
  • Assembly Discussion Thread
  • Unsolved
  • Views: 2379
  • Assembly RSS
Sep 20th, 2006
0

I have problem about Knapsack in ASM

Expand Post »
The knapsack problem

I try to write about this problem but i can't ...

This is a problem thai i have ..

Suppose you want your knapsack to weigh exactly 20 pounds,
and you have only five item, with weight 11,8,7,6,5 pounds.
For small number of items, humans are preety good at solving this problem by inspection.
So you can probably figure out that only the 8,7,5 combination of items adds up to 20.

....................................................................................................

Easy to understand is write about how to add item equal to 20
using ASM lan.
...................................................................................................
Similar Threads
Reputation Points: 10
Solved Threads: 0
Newbie Poster
2bejiw is offline Offline
5 posts
since Sep 2006
Sep 22nd, 2006
0

Re: I have problem about Knapsack in ASM

i have java code for that project

How can i change from java to ASM

public class Knapsack {

public static void main(String[] args) {

int[] x = { 11, 8, 7, 6, 5 }; // descendingly sorted inputs
int target = 20; // our target
boolean[] y = null; // y[i] will be true if x[i] is selected
boolean foundAnswer = false;
int sum = 0;
abc: for (int i = 0; i < x.length; i++) {
y = new boolean[x.length]; // all y(s) will be set default to 'false'
sum = x[i];
y[i] = true; // x[i] is selected
for (int j = i + 1; j < x.length; j++) {
if (sum + x[j] <= target) {
sum += x[j];
y[j] = true;
}

if (sum == target) {
foundAnswer = true; // now we found the answer.
break abc; // break out from outer most for loop
}
}
}
if (foundAnswer) {
System.out.println("Found Answer");
for (int i = 0; i < x.length; i++) {
if (y[i]) {
System.out.println(x[i]);
}
}
} else {
System.out.println("No Answer Found!!");
}
}
}

=============================================
Reputation Points: 10
Solved Threads: 0
Newbie Poster
2bejiw is offline Offline
5 posts
since Sep 2006
Sep 25th, 2006
0

Re: I have problem about Knapsack in ASM

i think u should ask AJ VasaKa na cuz she can help u
Reputation Points: 10
Solved Threads: 0
Newbie Poster
Achellis is offline Offline
1 posts
since Sep 2006

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 Assembly Forum Timeline: some assembly code help?
Next Thread in Assembly Forum Timeline: separating strings





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


Follow us on Twitter


© 2011 DaniWeb® LLC