回溯其实就是抽象图的遍历过程
这题数据实在太离谱了。
/**
* Return an array of arrays of size *returnSize.
* The sizes of the arrays are returned as *returnColumnSizes array.
* Note: Both returned array and *columnSizes array must be malloced, assume caller calls free().
*/
int temp[20];
void dfs(int** array,int*returnSize,int n,int k,int nowk,int index){//nowk 表示选了有几个数
if(nowk>k) return;
if(nowk==k){
for(int i=0;i<k;i++){
array[*returnSize][i]=temp[i];
}
(*returnSize)++;
return;
}
for(int i=index;i<=n;i++){
temp[nowk]=i;
dfs(array,returnSize,n,k,nowk+1,i+1);
temp[nowk]=0;
}
}
int** combine(int n, int k, int* returnSize, int** returnColumnSizes) {
*returnSize=0;
int** array=(int**)malloc(sizeof(int*)*200000);
for(int i=0;i<200000;i++) array[i]=(int*)malloc(sizeof(int)*k);
for(int i=0;i<20;i++) temp[i]=0;
dfs(array,returnSize,n,k,0,1);
int* column=(int*)malloc(sizeof(int)*(*returnSize));
for(int i=0;i<*returnSize;i++) column[i]=k;
*returnColumnSizes=column;
return array;
}
标签:returned,组合,nowk,int,returnSize,77,array From: https://www.cnblogs.com/llllmz/p/18059636