例:
上排: 0,1,2,3,4,5,6,7,8,9
下排: 6,2,1,0,0,0,1,0,0,0
#include <iostream>
using namespace std;
void arrange(int* count,int len){
int* temp = new int[len];
int n = 0;
for(int i=0;i<len;i++) {
memset(temp,0,len * sizeof(int));
memset(count,0,len * sizeof(int));
count[0] = i;
n = i;
while(true) {
if(temp[n] == 1) {
int c = 0;
for(int j = 0;j<len;j ++) {
if(count[j] == 0)
c++;
}
if(c == i ) {
for(j = 0;j<len;j ++) {
cout<<count[j]<<" ";
}
cout<<endl;
break;
} else {
break;
}
}
if(n == count[n])
temp[n] = 1;
count[n] += 1;
n = count[n];
}
cout<<"finish:"<<i<<endl;
}
}
int main(){
int count[10];
memset(count,0,10*sizeof(int));
arrange(count,10);
return 0;
}