Have to solve a problem? Try taking a nap.

But it has to be the right kind of nap  one that includes rapid eye movement, or REM, sleep, the kind that includes dreams.

Researchers led by Sara C. Mednick, an assistant professor of psychiatry at the University of California, San Diego, gave 77 volunteers word-association tests under three before-and-after conditions: spending a day without a nap, napping without REM sleep and napping with REM sleep. Just spending the day away from the problem improved performance; people who stayed awake did a little better on the 5 p.m. session than they had done on the 9 a.m. test. Taking a nap without REM sleep also led to slightly better results. But a nap that included REM sleep resulted in nearly a 40 percent improvement over the pre-nap performance.

The study, published June 8 in The Proceedings of the National Academy of Sciences, found that those who had REM sleep took longer naps than those who napped without REM, but there was no correlation between total sleep time and improved performance. Only REM sleep helped.

“Dreams are fanciful,” Dr. Mednick said. “They incorporate strange ideas that you would never have put together in waking life. In REM sleep, it becomes more likely that ideas might come together in a solution.”