/**
* 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[100];
void dfs(int** array,int n,int k,int* returnSize,int* column,int index,int count){
if(count>k || index>n+1) return ;
if(count==k){
array[*returnSize]=(int*)malloc(sizeof(int)*k);
for(int i=0;i<k;i++) array[*returnSize][i]=temp[i];
(*returnSize)++;
return;
}
temp[count]=index;
dfs(array,n,k,returnSize,column,index+1,count+1);
temp[count]=0;
dfs(array,n,k,returnSize,column,index+1,count);
}
int** combine(int n, int k, int* returnSize, int** returnColumnSizes) {
*returnSize=0;
int* column=(int*)malloc(sizeof(int)*200000);
for(int i=0;i<200000;i++) {
column[i]=k;
}
int** array=(int**)malloc(sizeof(int*)*200000);
*returnColumnSizes=column;
dfs(array,n,k,returnSize,column,1,0);
return array;
}
复试的时候内存也往大里开,以免问题。
标签:count,index,returned,组合,returnSize,int,77,array From: https://www.cnblogs.com/llllmz/p/18075268