拼凑钱币

来源:互联网 发布:mac os host 编辑:程序博客网 时间:2024/04/29 16:48
# usr/bin/env python# _*_ coding:utf-8 _*_'''给你六种面额 1、5、10、20、50、100 元的纸币,假设每种币值的数量都足够多,编写程序求组成N元(N为0~10000的非负整数)的不同组合的个数。 动态规划:dp[j] = dp[j] + dp[j-coins[i]], 条件是:j>coins[i]'''def GetNum(N):coins = [1, 5, 10, 20, 50, 100]l = 6       # l = len(coins)dp = [0]*(N+1)dp[0] = 1for i in range(l):for j in range(1, N+1):if j >= coins[i]:dp[j] += dp[j-coins[i]]return dp[N]if __name__ == '__main__':N = input()res = GetNum(N)print res

原创粉丝点击