public static void main(String[] args) throws IOException {
int[] inputArray = {1, 2, 3, 4, 5, 6, 7, 8};
int[] temp = {1,2,3,4};
int total = 0;
while(true){
int change = temp.length-1;
for(int i=0; i<temp.length; i++){
if(temp[i] == inputArray[inputArray.length-temp.length+i]){
change = i-1;
break;
}
}
temp[change] = temp[change]+1;
int num = 1;
for(int i=change+1; i<temp.length; i++){
temp[i] = temp[change]+(num++);
}
System.out.println((++total)+": "+temp[0]+","+temp[1]+","+temp[2]+","+temp[3]);
if(temp[0] == inputArray[inputArray.length-temp.length]){
break;
}
}
}
生成{1,2,..n}的字典序r-组合算法
最新推荐文章于 2021-08-30 21:41:25 发布