/**
* 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[30];
void dfs(int** array,int* column,int n,int k,int* returnSize,int num,int count){
if(count > k || num>n+1) return ;
if(count==k){
array[*returnSize]=(int*)malloc(sizeof(int)*k);
column[*returnSize]=k;
for(int i=0;i<count;i++) array[*returnSize][i]=temp[i];
(*returnSize)++;
return ;
}
temp[count]=num;
dfs(array,column,n,k,returnSize,num+1,count+1);
dfs(array,column,n,k,returnSize,num+1,count);
}
int** combine(int n, int k, int* returnSize, int** returnColumnSizes) {
*returnSize=0;
int* column=(int*)malloc(sizeof(int)*200000);
int** array=(int**)malloc(sizeof(int*)*200000);
dfs(array,column,n,k,returnSize,1,0);
*returnColumnSizes=column;
return array;
}
标签:count,组合,returnSize,int,77,column,num,array From: https://www.cnblogs.com/llllmz/p/18087908