#include<stdio.h> int count( int S[], int m, int n ) { if (n == 0) return 1; if (n < 0) return 0; if (m <=0 && n >= 1) return 0; return count( S, m - 1, n ) + count( S, m, n-S[m-1] ); } int main() { int N; scanf("%d", &N); int arr[] = {1, 5, 10, 50}; printf("%d\n", count(arr, 4, N)); return 0; }
| Input | Output | |
| Test Case 1 | 2 5 10 | 3 7 |
| Test Case 2 | 100 84 87 78 16 94 36 87 93 50 22 63 28 91 60 64 27 41 27 73 37 12 69 68 30 83 31 63 24 68 36 30 3 23 59 70 68 94 57 12 43 30 74 22 20 85 38 99 25 16 71 14 27 92 81 57 74 63 71 97 82 6 26 85 28 37 6 47 30 14 58 25 96 83 46 15 68 35 65 44 51 88 9 77 79 89 85 4 52 55 100 33 61 77 69 40 13 27 87 95 40 | 261 279 227 14 323 55 279 317 99 23 152 35 304 139 156 33 69 33 200 57 9 180 175 40 255 42 152 27 175 55 40 2 25 134 185 175 323 126 9 75 40 205 23 20 267 60 357 29 14 190 11 33 310 244 126 205 152 190 343 249 4 31 267 35 57 4 88 40 11 130 29 337 255 85 13 175 52 161 78 103 285 6 221 232 291 267 2 106 118 364 47 143 221 180 66 10 33 279 330 66 |
Labels: c program, coin counting, gather A rupees, recursion, source code