#include #include int total=0,in=0; void computeSum(int a[],int amountLeft,int r1Left,int r2Left, int r5Left); int checkedAndPrinted[25][3]; int main() { int array[3]={0,0,0}, m=5,n = 5,k=3,s=15,i=0,j=0; //index=0; for(i=0;i<25;i++) { for(j=0;j<3;j++) checkedAndPrinted[i][j]= 0; } computeSum(array,s,m,n,k); printf("Total ways : %d \n",total); return 0; } void computeSum(int a[],int amountLeft,int r1Left,int r2Left, int r5Left) { int i=0,ch=0; if(amountLeft == 0) { for(i=0;i 0) { a[0]++; computeSum(a,amountLeft-1,r1Left-1,r2Left,r5Left); a[0]--; } } if(amountLeft == 2) { if(r1Left > 0) { a[0]++; computeSum(a,amountLeft-1,r1Left-1,r2Left,r5Left); a[0]--; } if(r2Left > 0) { a[1]++; computeSum(a,amountLeft-2,r1Left,r2Left-1,r5Left); a[1]--; } } if(amountLeft >=3) { if(r1Left > 0) { a[0]++; computeSum(a,amountLeft-1,r1Left-1,r2Left,r5Left); a[0]--; } if(r2Left > 0) { a[1]++; computeSum(a,amountLeft-2,r1Left,r2Left-1,r5Left); a[1]--; } if(r5Left > 0) { a[2]++; computeSum(a,amountLeft-5,r1Left,r2Left,r5Left-1); a[2]--; } } }