The continuous shrinkage of minimum feature size in integrated circuit (IC) fabrication incurs more and more serious distortion in the optical projection lithography process, generating circuit patterns that deviate significantly from the desired ones. Conventional resolution enhancement techniques (RETs) are facing critical challenges in compensating such increasingly severe distortion. In this paper, we adopt the approach of inverse lithography in the mask design, which is a branch of design methodology to treat it as an inverse mathematical problem. We focus on using pixel-based algorithms to design alternating phase-shifting masks with minimally distorted output, with the goal that the patterns generated should have high contrast and low dose sensitivity. This is achieved with a dynamic-programming-based initialization scheme to pre-assign phases to the layout when alternating phase-shifting masks are used. Pattern fidelity and worst case slopes are shown to improve with this initialization scheme, which are important for robustness considerations.