In theory you should be able to use the names of famous people in fiction, but there is nothing to stop those real people from suing you if they choose to. Even if they don't expect to win, they can make your life miserable, and they probably have a lot more money than you to pay legal fees.
In terms of your legal rights, the key thing is whether you are slandering them or not. If you are simply mentioning their name, as in "I was walking down the road, I saw Stephen King and I was so surprised I nearly fell into a ditch," it would be hard to argue that you are damaging his personal name in any way. However, if you said "I saw Stephen King beating an old lady with a steel rod" then you might be in danger of legal action. Of course, if you really did see him beating an old lady with a steel rod then you could potentially win a court case because it really happened. (You would be really inviting a court case though, and would waste a lot of time you could have spent writing your novel.)
When it comes down to it, it might not be worth it to risk legal action, and you can only really be safe if you have written permission from the person named. If an editor wants to publish your book they will advise you to change anything that might get you in trouble, so maybe just write what you want, with that in mind.