我想要做的是找到一個一維數組的每個排列並重復其內容。有像next_permutation這樣的函數,但是有重複的排列嗎?
例如
int array[]={1,2,3};
for(i=0;i<3;i++){
next_permutation(array,array+3)
for(int j=0;j<=3;j++){
printf("%d ",array[j]);
}
printf("\n");
}
將返回:
1 2 3
1 3 2
2 1 3
etc...
我希望函數返回:
1 1 1
1 1 2
1 2 1
2 1 1
1 2 2
2 2 1
2 1 2
1 1 3
1 3 1
3 1 1
etc...
有沒有能夠做到這一點的功能?
由於提前, 埃裏克
這是相關的:http://stackoverflow.com/questions/1944508/arbitrary-digit-counter – Aziz 2012-03-24 18:06:54
這也是:http://stackoverflow.com/questions/2380962/generate-all-combinations-of-arbitrary -alphabet向上到任意長度的 – Aziz 2012-03-24 18:08:43