You certainly easily can: effectively free (subsidized by tax payers).
The house-the-homeless programs run during the Bush and Obama administrations dramatically reduced chronic homelessness in most of the US, pushing it to a record low per capita.
San Francisco is one of the wealthiest places on earth. They intentionally choose to allow the human rights violation of mass, particularly chaotic homelessness to continue in the city. Morally they own it, period. There are obvious, highly effective solutions that have been used elsewhere.
That's not building cheap housing that drug users can afford. It's just getting someone else to pay.
Deinstitutionalization has contributed to SF's homeless problem, as many mentally handicapped people self medicate with illegal substances.