Напишите рекурсивную функцию C для вычисления комбинации
Рекурсивное определение для вычисления комбинации n объектов, взятых k за один раз, может быть определено следующим образом:
C (n, k) = {1, Если k = 0 или n = k
C (n-1, k) + C (n-1, k-1), Если n> k> 0
}
Написать рекурсивную функцию C, чтобы реализовать выше.
Что я уже пробовал:
#include<iostream> 02 #include<stdlib.h> 03 using namespace std; 04 05 void combination(int m , int n , int result[]); 06 void output(int result[]); 07 int taco; 08 09 int main(int argc , char** argv) 10 { 11 int m, n; 12 int* result; 13 m = atoi(argv[1]); 14 taco = n = atoi(argv[2]); 15 result = (int*)malloc(sizeof(int)*n); //Dynamic array. 16 //The size of array is same with n. 17 for(int i = 0 ; i < n ; i++) result[i] = 0; 18 combination(m , n , result); 19 } 20 21 22 void combination(int m , int n , int result[]) 23 { 24 //You have to write your algorithm here 25 } 26 void output(int result[]) //You can call output function after you put result in result[]. 27 { 28 cout<<"< "; 29 for(int i = taco - 1 ; i >=0 ; i--) 30 cout<<result[i]<<" "; 31 cout<<">"<<endl; 32 }