All permutations of length k from n characters with repetition in CPP

后端 未结 4 1426
Happy的楠姐
Happy的楠姐 2020-12-15 14:43

I would like to know if there is already an implementation in CPP to find all permutations of n characters of length k(1,2,3,4 etc) with repetitions. I hope there is but i c

4条回答
  •  -上瘾入骨i
    2020-12-15 15:18

    This just isn't a permutation, which probably explains why you can't find an answer.

    What you are actually asking is how to print the numbers 0..k-1 in base n, using digits A,B,C,D. I'll rewrite your example with familiar digits 0,1,2,3 :

    00
    01
    02
    03
    10
    11
    12
    13
    ..
    33
    

    There's no standard C++ method for this, but now that you know what it's called there's plenty of code on the web. Or just write it yourself. Hint: the last digit of i has value i % n.

提交回复
热议问题