#55265: cpp_answer


yp11451202@yphs.tp.edu.tw (705-38黃鈺潤)


#include <iostream>
#include <vector>
#include <string>
#include <sstream>

using namespace std;

// 定義可用的面額
int coins[] = {1, 5, 10, 20, 50, 100, 200, 500, 1000, 2000};
long long dp[50001];

void solve() {
    // 預處理 DP 表格
    dp[0] = 1;
    for (int coin : coins) {
        for (int i = coin; i <= 50000; i++) {
            dp[i] += dp[i - coin];
        }
    }

    string line;
    while (getline(cin, line)) {
        if (line == "0") break;

        stringstream ss(line);
        int val, total = 0;
        vector<int> input_coins;
        
        // 讀取該行所有硬幣並加總
        while (ss >> val) {
            total += val;
            input_coins.push_back(val);
        }

        if (total == 0) continue;

        // 計算結果:總組合數 - 1 (扣除題目給定的那組特定組合)
        // 根據範例,若輸入 10 10,結果為 dp[20] - 1 = 10 - 1 = 9
        cout << dp[total] - 1 << endl;
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}