A variational approach to the inverse photolithography problem