Interplay of charge density wave and spin density wave in high-Tc superconductors