This function finds whether the amount can be given to Mila or not i.e. if any sum of coins with gila equals amount to be distributed(x) */
| 5 | i.e. if any sum of coins with gila equals amount to be distributed(x) |
| 6 | */ |
| 7 | bool findsum(int a[],int n,int sum) |
| 8 | { |
| 9 | if(sum==0) |
| 10 | return 1; |
| 11 | if(sum!=0 && n==0 ) // If there are no coins and n is greater than 0, then no solution exist |
| 12 | return 0; |
| 13 | if(a[n-1]>sum) // i.e. a[n-1] can't be included in solution |
| 14 | return findsum(a,n-1,sum); |
| 15 | return (findsum(a,n-1,sum)||findsum(a,n-1,sum-a[n-1])); // is sum of solutions including a[n-1] or excluding a[n-1] |
| 16 | } |
| 17 | |
| 18 | int money(int a[],int n,int m,int sum) |
| 19 | { |