当前位置:网站首页>Change tax for 2
Change tax for 2
2022-06-13 02:33:00 【Prodigal son's private dishes】
difficulty : secondary
Give coins of different denominations and a total amount . Write a function to calculate the number of coin combinations that can add up to the total amount . Suppose that there are infinite coins of each denomination .
Example 1:
Input : amount = 5, coins = [1, 2, 5] Output : 4 explain : There are four ways to make up the total amount : 5=5 5=2+2+1 5=2+1+1+1 5=1+1+1+1+1
Example 2: Input : amount = 3, coins = [2] Output : 0 explain : Use only face value 2 We can't make up the total amount of 3.
Example 3: Input : amount = 10, coins = [10] Output : 1
Be careful , You can assume :
0 <= amount ( Total sum ) <= 5000
1 <= coin ( The denomination of the coin ) <= 5000
There are no more kinds of coins 500 Kind of
The result is in line with 32 Bit sign integer
Code
class Solution {
public int change(int amount, int[] coins) {
// Recursive expression
int[] dp = new int[amount + 1];
// initialization dp Array , Indicates that the amount is 0 There is only one case , That is to pretend nothing
dp[0] = 1;
for (int i = 0; i < coins.length; i++) {
for (int j = coins[i]; j <= amount; j++) {
dp[j] += dp[j - coins[i]];
}
}
return dp[amount];
}
}
边栏推荐
- Termux SSH first shell start
- cmake_ example
- 04 route jump and carry parameters
- 0- blog notes guide directory (all)
- Stm32f4 DMA Da sine wave generator keil5 Hal library cubemx
- ROS learning-6 detailed explanation of publisher programming syntax
- Impossible d'afficher le contenu de la base de données après que l'idée a utilisé le pool de connexion c3p0 pour se connecter à la base de données SQL
- Leetcode 926. 将字符串翻转到单调递增 [前缀和]
- js-dom
- 03 认识第一个view组件
猜你喜欢

How to destroy a fragment- How to destroy Fragment?
![Leetcode 473. 火柴拼正方形 [暴力+剪枝]](/img/3a/975b91dd785e341c561804175b6439.png)
Leetcode 473. 火柴拼正方形 [暴力+剪枝]

L1 regularization and its sparsity
![[reading papers] dcgan, the combination of generating countermeasure network and deep convolution](/img/31/8c225627177169f1a3d6c48fd7e97e.jpg)
[reading papers] dcgan, the combination of generating countermeasure network and deep convolution

Armv8-m learning notes - getting started

A real-time target detection model Yolo

Automatic differential reference

Paper reading - joint beat and downbeat tracking with recurrent neural networks

Chapter7-10_ Deep Learning for Question Answering (1/2)

Image table solid line and dashed line detection
随机推荐
[keras] train py
Leetcode 450. 删除二叉搜索树中的节点 [二叉搜索树]
Huawei equipment is configured with CE dual attribution
Huffman tree and its application
[analysis notes] source code analysis of siliconlabs efr32bg22 Bluetooth mesh sensorclient
哈夫曼树及其应用
redis 多个服务器共用一个
Understand speech denoising
Mean Value Coordinates
[reading point paper] deeplobv3 rethinking atlas revolution for semantic image segmentation ASPP
Opencvsharp4 handwriting recognition
04路由跳转并携带参数
Matlab: find the inner angle of n-sided concave polygon
Chapter7-13_ Dialogue State Tracking (as Question Answering)
[keras] generator for 3D u-net source code analysis py
How can intelligent safe power distribution devices reduce the occurrence of electrical fire accidents?
在IDEA使用C3P0连接池连接SQL数据库后却不能显示数据库内容
Automatic differential reference
[dest0g3 520 orientation] dest0g3, which has been a long time since we got WP_ heap
Priority queue with dynamically changing priority