@@ -0,0 +1,964 @@
+package com.linbo.algs.leetcode;%0A%0Aimport java.util.Stack;%0A%0A/**%0A * Created by @linbojin on 11/2/17.%0A *  classic back pack problems%0A */%0Apublic class BackPack %7B%0A%0A  public static void solution(int%5B%5D w, int t) %7B%0A    int n = w.length;%0A    Stack%3CInteger%3E s = new Stack%3CInteger%3E();%0A%0A    int i = 0;%0A    while (t %3E 0 && i %3C= n-1) %7B%0A      if ((t - w%5Bi%5D) == 0 %7C%7C (t-w%5Bi%5D %3E 0 && i %3C n-1)) %7B%0A        s.push(i);%0A        t -= w%5Bi%5D;%0A      %7D%0A      if (t == 0) %7B%0A        System.out.println(%22indexes: %22 + s);%0A        System.out.print(%22values:  %5B%22);%0A        for (int m: s) %7B%0A          System.out.print(w%5Bm%5D + %22  %22);%0A        %7D%0A        System.out.println(%22%5D%22);%0A        return;%0A      %7D else %7B%0A        if (i == n-1 && !s.isEmpty()) %7B%0A          i = s.pop();%0A          t += w%5Bi%5D;%0A        %7D%0A        i++;%0A      %7D%0A    %7D%0A    System.out.println(%22no solution!%22);%0A  %7D%0A%0A  public static void main(String%5B%5D args) %7B%0A    int%5B%5D w = %7B4, 7, 3, 5, 4, 2%7D;%0A    int t = 10;%0A%0A    BackPack.solution(w, t);%0A  %7D%0A%7D%0A

add backpack solution