zoukankan      html  css  js  c++  java
  • 拼凑面额(动态规划)

    题目描述

    给你六种面额1、5、10、20、50、100元的纸币,假设每种币值的数量都足够多,编写程序求组成N员(N为0-10000的非负整数)的不同组合的个数。

    输入描述:

    输入为一个数字N,即需要拼凑的面额

    输出描述:

    输出也是一个数字,为组成N的组合个数。
    示例1

    输入

    5
    

    输出

    2
     1 import java.util.Scanner;
     2 /**
     3  * 
     4  *  拼凑面额
     5  *     动态规划
     6  *         横坐标: 1——n
     7  *         纵坐标:  面值
     8  *        值:  种类数       
     9  * @author Dell
    10  *
    11  */
    12 public class Main{
    13 public static void main(String[] args) {
    14     Scanner sc= new Scanner(System.in);
    15     int n = sc.nextInt();
    16     long[] dp = new long[n+1];
    17     // 初始化
    18     for (int i = 0; i < dp.length; i++) {
    19         dp[i] = 0;
    20     }
    21     int[] a = {1,5,10,20,50,100};
    22     // 装入0
    23     dp[0] = 1;
    24      // 动态规划
    25     for (int i = 0; i < a.length; i++) {
    26     for (int j = 1; j < dp.length; j++) {
    27             if (j>=a[i]) {    
    28                 dp[j] = dp[j]+dp[j-a[i]];
    29             }
    30         }
    31     }
    32     System.out.println(dp[n]);
    33 }
    34 }
  • 相关阅读:
    Swagger2 添加HTTP head参数
    获取枚举类型描述
    JS设置cookie、读取cookie、删除cookie
    ES6中Promise的入门(结合例子)
    阮一峰的ES6---Promise对象
    model_util.py
    IfcSpatialElementType
    labelme coco
    python opencv KeyPoint
    IfcSpatialZoneType
  • 原文地址:https://www.cnblogs.com/the-wang/p/8981472.html
Copyright © 2011-2022 走看看