cpp implementation of Permutation II