Banking Saving Algorithm in C using recursion

3

I'm having doubts about a bank draw algorithm in C. First of all, it is better to pass the statement:

  

ATMs in banks are a great invention, but sometimes we need money exchanged and the machine delivers $ 100 bills. Other times, we want to get a slightly higher value and for safety reasons would like to receive everything in $ 100 bills, but the machine delivers a lot of $ 20 bills. Banco Inteligente is trying to minimize this problem by giving customers the ability to choose the amount of notes at the time of withdrawal. To do this, they need your help to know, given the S value of the serve and how many notes of each value the machine has, how many different ways there are to deliver the value S. The bank provides notes of 2, 5, 10, 20, 50 and 100. For example, if S = 22 and the number of notes of each value is N2 = 5, N5 = 4, N10 = 3, N20 = 10, N50 = 0 and N100 = 10, then there are 4 distinct forms of machine to deliver the value of the service: 20 + 2, 10 + 10 + 2, 10 + 5 + 5 + 2 and 5 + 5 + 5 + 5 + 2.      

Input

     

The first line of the entry contains an integer S, the value of the service. The second line contains six integers N2, N5, N10, N20, N50 and N100, respectively, the number of notes of values 2,5,10,20,50 and 100 available on the machine.      

Output

     

Your program should print an integer, the number of distinct forms of the machine deliver the serve.

I just do not know how to do to count as many possibilities, even more that there are many ways. So far this was what I was able to implement in my code (The forms function obviously is not implemented at all):

    #include <stdio.h>

typedef struct{
  int q;
  int v;
}din;

int start(din n[],int t,int i){
  if(t>=n[i].v) return i;
  else return start(n,t,i-1);
}

int forms(din n[6],int t,int i){
  int x,k=t,c=0;
  if(n[x].q==0) return forms(n,t,i-1);
  else{
    if(k==0){
      c++;
    }
    else{ 
    }
  } 
}

int main(void){
  int t,x;
  din n[6];
  scanf("%d",&t);
  for(x=0;x<6;x++) scanf("%d",&n[x].q);
  for(x=0;x<6;x++){
    if(x==0) n[x].v=2;
    else if(x==1) n[x].v=5;
    else if(x==2) n[x].v=10;
    else if(x==3) n[x].v=20;
    else if(x==4) n[x].v=50;
    else if(x==5) n[x].v=100;
  }
  printf("%d\n",forms(n,t,start(n,t,5));
  return 0;
 } 
    
asked by anonymous 23.03.2018 / 23:14

0 answers