int count_min(int sum) { int min = MAX + 1; if (sum < 0) return -1; if (sum == 0) return 0; if (min_sum[sum]) return min_sum[sum]; for (int i = 0, count = 0; i < SIZE(coin_list); i++, count = 0) { int r = count_min(sum - coin_list[i]); if (r < 0) continue; count = 1 + r; if (min > count) min = count; } if (min == MAX + 1) min_sum[sum] = 0; else min_sum[sum] = min; return min_sum[sum]; }
int main(int argc, char **argv) { if (argc != 2) return -1; int sum = atoi(argv[1]); if (sum >= MAX) return -1; printf("Min Change :%d\n", count_min(sum)); return 0; }
static void *count_new(t_floatarg minval, t_floatarg maxval, t_floatarg onflag, t_floatarg autoflag) { t_count *x = (t_count *)pd_new(count_class); count_min(x, minval); count_max(x, maxval); x->x_on = (onflag != 0); count_autoreset(x, autoflag); x->x_count = x->x_min; inlet_new((t_object *)x, (t_pd *)x, &s_float, gensym("ft1")); outlet_new((t_object *)x, &s_signal); return (x); }
static void count_list(t_count *x, t_symbol *s, int ac, t_atom *av) { int i; if (ac > 4) ac = 4; for (i = 0; i < ac; i++) if (av[i].a_type != A_FLOAT) break; switch (i) { case 4: count_autoreset(x, av[3].a_w.w_float); case 3: x->x_on = (av[2].a_w.w_float != 0); case 2: count_max(x, av[1].a_w.w_float); case 1: count_min(x, av[0].a_w.w_float); default: x->x_count = x->x_min; } }