Permutations with repetition
n 중첩 for문
Permutations with repetition) n{\displaystyle \Pi }r( {
size_t length = 4;
vector<size_t> vidxs;
vector<size_t> vacc;
vector<size_t> idxs;
size_t total = 1, cnt = 0;
for (size_t i = 0; i < length; i++)
{
vidxs.push_back(length);
vacc.push_back(total);
total *= length;
}
idxs.resize(vidxs.size());
while (total > cnt)
{
idxs[0] = cnt%vidxs[0];
for (size_t i = 1; i < length; ++i)
{
idxs[i] = cnt / vacc[i];
idxs[i] = idxs[i] % vidxs[i];
}
for (int i = length - 1; i >= 0; --i){//to do
cout << idxs[i] << " ";
}
cout << endl;
++cnt;
}
cout << cnt;
}