Detailed explanation of the change problem of dynamic programming
Change problem: The amount of change required is W, the face values of coins are (d1, d2, d3,..., dm), how many coins are needed at least.
Question: The amount of change required is 8. The face values of coins are (1, 3, 2, 5). How many coins are needed at least.
Let F(j) represent the minimum number of change when the total amount is j, F(0) = 0, W represents the change amount, and there is a pile of change {d1, d2, d3,..., dm} . Also based on previous experience, to achieve j, it must be the number of coins with a face value of j – di(1 = di, that is, F (j) = F(j - di) + 1, j >= di.
Java
1 package com.algorithm.dynamicprogramming; 2 3 import java.util.Arrays; 4 5 /** 6 * 找零问题 7 * Created by yulinfeng on 7/5/17. 8 */ 9 public class Money {10 public static void main(String[] args) {11 int[] money = {1, 3, 2, 5};12 int sum = 8;13 int count = money(money, sum);14 System.out.println(count);15 }16 17 private static int money(int[] money, int sum) {18 int[] count = new int[sum + 1];19 count[0] = 0;20 for (int j = 1; j = 0) {24 int temp = count[j - money[i]] + 1; //当前所需硬币数25 if (temp
## Python3
1 #coding=utf-8 2 def charge_making(money, num): 3 ''' 4 找零问题 5 ''' 6 count = [0] * (num + 1) 7 count[0] = 0 8 for j in range(1, num + 1): 9 minCoins = j10 for i in range(len(money)):11 if j - money[i] >= 0:12 temp = count[j - money[i]] + 113 if temp <div class="cnblogs_code"></div><p><em>tag<strong></strong></em></p>
The above is the detailed content of Detailed explanation of the change problem of dynamic programming. For more information, please follow other related articles on the PHP Chinese website!

The article discusses using Maven and Gradle for Java project management, build automation, and dependency resolution, comparing their approaches and optimization strategies.

The article discusses creating and using custom Java libraries (JAR files) with proper versioning and dependency management, using tools like Maven and Gradle.

The article discusses implementing multi-level caching in Java using Caffeine and Guava Cache to enhance application performance. It covers setup, integration, and performance benefits, along with configuration and eviction policy management best pra

The article discusses using JPA for object-relational mapping with advanced features like caching and lazy loading. It covers setup, entity mapping, and best practices for optimizing performance while highlighting potential pitfalls.[159 characters]

Java's classloading involves loading, linking, and initializing classes using a hierarchical system with Bootstrap, Extension, and Application classloaders. The parent delegation model ensures core classes are loaded first, affecting custom class loa


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

SublimeText3 Linux new version
SublimeText3 Linux latest version

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software