Eating the right foods can prevent dementia and keep your mind sharp as you age, a new study suggests.