public CuttingResult getReward(Tilia x){

		int side = x.getSide();
		
		//Check if you have computed this before
        if(!tabel.containsKey(side)){
            ArrayList<Integer> pieces = new ArrayList<Integer>();
            pieces.add(x.getSide());
            // First two variables in CuttingResult are not used
            CuttingResult best = new CuttingResult(0, 0, x.getReward(), pieces);


    		// Try possible cuts
    		for (int i =1 ; i < x.getSide() ; i++){
    			ArrayList<Integer> pieces_tmp = new ArrayList<Integer>();
    			long sum =0;
    			//Try different cuts
    			for (Tilia tilia : x.cut(i)){
                    //Process smaller pieces
    				CuttingResult temp = getReward(tilia);
    				for(int j=0; j < temp.getPieces().size();j++){
    					pieces_tmp.add(temp.getPieces().get(j));
    				}
    					sum+=temp.getReward();
    				
                  
    			}
                //Select optimal result
                if (sum > best.getReward()){
                  best.setPieces(pieces_tmp);
                  best.setReward(sum);
    			}
    		}

		// Save optimal result
		tabel.put(side, best);
		return best;
	}
        else return tabel.get(side);
	}