public static void main(String[] args) {

    int W = 10;
    int[] w = new int[] {0,1,2,5,7,2,1,2,4,6};
    int[] v = new int[] {0,1,3,5,2,5,6,4,5,5};
    int items = w.length - 1; 
    int[][] A = new int[w.length][W+1];

    for (int i = 1; i < w.length; i++) {
      for (int j = 0; j <= W; j++) {
        A[i][j] = max(A[i-1][j], j >= w[i] ? A[i-1][j-w[i]] + v[i] : 0);
      }
    }
    int i = A.length - 1;
    int j = A[0].length - 1;
    while (i >= 1 && j >= 0) {
      System.out.println("i: " + i + " j: " + j);
      if (A[i-1][j] < (j > w[i] ? A[i-1][j-w[i]] + v[i] : 0)) {
        // elegido
        System.out.println("Si: " + i); 
        j -= w[i]; 
        
      } else {
        // no elegido
        System.out.println("No: " + i);
      } 
      i--;
    }
    System.out.print("w: "); printa(w);
    System.out.print("v: "); printa(v);
    print(A);
  }