Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import BackPack.BackPack;
- import BackPack.Item;
- import java.util.Vector;
- public class main {
- public static void main(String[] argc){
- Vector<Item> listOfItems = new Vector<>();
- Item it = new Item(10,100,"Notebook");
- Item it2 = new Item(15,1500,"Notebook2");
- Item it3 = new Item(1000,100,"Notebook3");
- Item it4 = new Item(12000,10000,"Notebook4");
- Item it5 = new Item(10,12,"Notebook5");
- listOfItems.add(it);
- listOfItems.add(it2);
- listOfItems.add(it3);
- listOfItems.add(it4);
- listOfItems.add(it5);
- BackPack BP = new BackPack(100);
- /*for(int i=0;i<listOfItems.size();i++){
- System.out.println(listOfItems.elementAt(i).getCorrelation());
- }*/
- int[][] solution = new int[listOfItems.size()][(int)BP.getCapacity()];
- for(int i=0;i<BP.getCapacity();i++){
- solution[0][i]=0;
- }
- for(int i=1;i<listOfItems.size();i++){
- for (int j = 0; j < BP.getCapacity(); j++) {
- if (listOfItems.elementAt(i).getWeight() > j) {
- solution[i][j] = solution[i - 1][j];
- } else {
- solution[i][j] = Math.max(solution[i - 1][j], solution[i - 1]
- [j - (int) listOfItems.elementAt(i).getWeight()] + (int) listOfItems.elementAt(i).getCost());
- }
- }
- }
- for( int i=0;i<listOfItems.size();i++){
- for (int j=0;j<BP.getCapacity();j++){
- System.out.print(solution[i][j]+" ");
- }
- System.out.println();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement