private static int val(int id, int remW, int iterations) {
		
		
		if(iterations == 0) {
			return 0;
		}
		
		if(remW == 0) {
			return 0;
		}
		
		if(id == W.length) {
			return 0;
		}
		
		if(W[id] > remW) {
			
			if(val[id+1][remW][iterations] == -1) {
				
				val[id][remW][iterations] = val(id+1, remW, iterations);
				
			} else {
				
				val[id][remW][iterations] = val[id+1][remW][iterations];
				
			}
		}
		
		if(W[id] <= remW) {
//			int x = val(id+1, remW, iterations);
//			int y = W[id] + val(id+1, remW - W[id], iterations -1);
			
			if(val[id + 1][remW][iterations] == -1) {
				
				val[id][remW][iterations] = val(id + 1, remW, iterations);
			
			}
			
			if(val[id + 1][remW - W[id]][iterations-1] == -1) {
				
				val[id][remW - W[id]][iterations] = W[id] + val(id + 1, remW - W[id], iterations - 1);
				
			} else {
				iterations--;
			}

			val[id][remW][iterations] = Math.max(val[id][remW][iterations], val[id][remW - W[id]][iterations]);
			return val[id][remW][iterations];
		}
		
		return 0;
	}