。
A good idea suddenly occurred to him.
Literal
Good idea [subject-が] his [of-の] head [in-に] suddenly came-to-mind.
ふと ('suddenly, by chance, all of a sudden') is an adverb for unexpected, spontaneous occurrences — often for thoughts, memories, or impulses. Pair with 浮かぶ ('come to mind'). 頭に ('in one's head') localizes where the idea surfaces.