Skip to content

Instantly share code, notes, and snippets.

@HinataYukari
Created December 21, 2017 19:49
Show Gist options
  • Save HinataYukari/198c0d67d21e1139681e1047e804c912 to your computer and use it in GitHub Desktop.
Save HinataYukari/198c0d67d21e1139681e1047e804c912 to your computer and use it in GitHub Desktop.
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
#define rep(n, i) for(int i = 0; i < n; i++)
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
void solve(void){
int n, m;
scanf("%d %d\n", &n, &m);
int coins[m], pays[n+1];
rep(m, i) scanf("%d ", &coins[i]);
rep(n+1, i) pays[i] = i;
rep(m, i){
for (int j = coins[i]; j < n+1; j++){
pays[j] = MIN(pays[j], pays[j - coins[i]]+1);
}
}
printf("%d\n", pays[n]);
}
int main(void){
solve();
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment