uva_357Let Me Count The Ways

来源:互联网 发布:交易师软件下载 编辑:程序博客网 时间:2024/05/18 18:00
#include <cstdio>#include <cstring>#include <algorithm>using namespace std;#define COIN    5#define MAXN    30000+10unsigned long long dp[MAXN];int coin[] = {1, 5, 10, 25, 50};void complete_knapsack(void){        memset(dp, 0, sizeof(dp)); dp[0] = 1;        for(int i = 0; i < COIN; i ++) {                for(int j = 1; j < MAXN; j ++) {                        if( j < coin[i] ) {                                continue;                        }                        dp[j] += dp[j-coin[i]];                }        }}int main(int argc, char const *argv[]){#ifndef ONLINE_JUDGE        freopen("test.in", "r", stdin);#endif        int n;        complete_knapsack();        while( ~scanf("%d", &n) ) {                if( 1 == dp[n] ) {                        printf("There is only 1 way to produce %d cents change.\n", n);                }                else {                        printf("There are %llu ways to produce %d cents change.\n", dp[n], n);                }        }        return 0;}

原创粉丝点击