zoukankan      html  css  js  c++  java
  • uva 357 Let Me Count The Ways(01背包)

    题目连接:357 - Let Me Count The Ways


    题目大意:有5种硬币, 面值分别为1、5、10、25、50,现在给出金额,问可以用多少种方式组成该面值。


    解题思路:和uva674是一样的, 只是上限不一样, 还有注意下输出。


     

    #include <stdio.h>
    #include <string.h>
    const int N = 30005;
    const int val[5] = {1, 5, 10, 25, 50};
    
    long long cnt[N];
    
    void Init() {
        memset(cnt, 0, sizeof(cnt));
        cnt[0] = 1;
        for (int i = 0; i < 5; i++) {
    	for (int j = val[i]; j < N; j++)
    	    cnt[j] += cnt[j - val[i]];
        }
    }
    
    int main() {
        Init();
        int n;
        while (scanf("%d", &n) == 1) {
    	if (cnt[n] <= 1)
    	    printf("There is only 1 way to produce %d cents change.
    ", n);
    	else
    	    printf("There are %lld ways to produce %d cents change.
    ", cnt[n], n);
        }
        return 0;
    }
    


  • 相关阅读:
    每日日报46
    每日日报45
    每日日报44
    每日日报43
    每日日报42
    每日日报41
    每日日报40
    每日日报之一周总结
    每日日报
    每日日报
  • 原文地址:https://www.cnblogs.com/keanuyaoo/p/3306245.html
Copyright © 2011-2022 走看看