"""
找零问题 — 贪心算法
使用最少硬币凑出指定金额
"""

def min_coins_greedy(coins, amount):
    """贪心找零（硬币面额需满足贪心选择性质）"""
    coins_sorted = sorted(coins, reverse=True)
    result = []
    remaining = amount

    for coin in coins_sorted:
        while remaining >= coin:
            result.append(coin)
            remaining -= coin

    return result

def min_coins_dp(coins, amount):
    """动态规划找零（通用解法）"""
    MAX = float('inf')
    dp = [MAX] * (amount + 1)
    dp[0] = 0

    for i in range(1, amount + 1):
        for coin in coins:
            if i >= coin:
                dp[i] = min(dp[i], dp[i - coin] + 1)

    return dp[amount] if dp[amount] != MAX else -1

if __name__ == "__main__":
    coins = [1, 5, 10, 25]
    amount = 63

    greedy_result = min_coins_greedy(coins, amount)
    dp_result = min_coins_dp(coins, amount)

    print(f"硬币面额: {coins}")
    print(f"需要凑出: {amount}")
    print(f"贪心结果: {greedy_result} (共 {len(greedy_result)} 枚)")
    print(f"DP最少数量: {dp_result} 枚")
