UVA 357 - Let Me Count The Ways

来源:互联网 发布:免费网络图绘制软件 编辑:程序博客网 时间:2024/06/01 10:41

相同类型的题做过好的了, 简单dp问题。


#include <iostream>#include <cstdio>const int size = 30000 + 100;long long d[size];int c[] = {1 , 5 , 10 , 25 , 50};int main(){for(int i = 0 ; i < size ; ++i) d[i] = i / 5 + 1;for(int i = 2 ; i < 5 ; ++i){for(int j = 0 ; j < size ; ++j) if(j >= c[i])d[j] += d[j-c[i]];}int n;while(scanf("%d" , &n) == 1){if(d[n] > 1) printf("There are %lld ways to produce %d cents change.\n" , d[n] , n);else printf("There is only 1 way to produce %d cents change.\n" , n);}return 0;}


0 0