Imperfect patent protection, licensing, and R&D investment