Another coin change problem, much the same as 357. I experimented replacing cin/cout by scanf/printf, and the runtime do reduced dramatically!
CODE
#include <iostream>
enum { MAX = 7489, COINS = 5 };
int main(){
const int coin[] = {1, 5, 10, 25, 50};
long long w[MAX+1] = {};
w[0] = 1;
for(int i=0; i<COINS; ++i)
for(int j=coin[i]; j<=MAX; ++j)
w[j] += w[j-coin[i]];
int n;
while( scanf("%d", &n) != EOF )
printf("%d\n", w[n]);
return 0;
}
No comments:
Post a Comment