public int getPayments(int i, int j, int k, int l) {
    if (minpayments[i][j][k][l] == -1) {
      if (i == k && j == l) {
        minpayments[i][j][k][l] = 0;
      } else {
        int min = Integer.MAX_VALUE;
        
        for (int row = i; row < k; row++) {
          min = Math.min(min, getPayments(i, j, row, l) + getPayments(row + 1, j, k, l));
        }
        
        for (int col = j; col < l; col++) {
          min = Math.min(min, getPayments(i, j, k, col) + getPayments(i, col + 1, k, l));
        }
        
        minpayments[i][j][k][l] = numraisins[i][j][k][l] + min;
      }
    }
    return minpayments[i][j][k][l];
  }