#include <stdio.h>
#include <string.h>
#include <stdlib.h>

int DP[10000];

int min(int a, int b){
    return (a > b) ? b : a;
}

int c[3] = {1, 3, 4};

int coin(int n){
    if(n == 0) return 0;
    if(DP[n] != -1) return DP[n];
    
    int result = 2147483647;

    for(int i=0; i<3; i++){
        if(n >= c[i]){
            result = min(result, coin(n-c[i])+1);
        }
    }
    DP[n] = result;
    return result;
}

int main() {
    int n;
    scanf("%d", &n);

    for(int i=0; i<=n; i++)
        DP[i] = -1;

    printf("%d", coin(n));
    
    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: