首页
题库
面试
求职
学习
竞赛
More+
所有博客
搜索面经/职位/试题/公司
搜索
我要招人
去企业版
登录 / 注册
首页
>
试题广场
>
兑换零钱(二)
[编程题]兑换零钱(二)
热度指数:2338
时间限制:C/C++ 1秒,其他语言2秒
空间限制:C/C++ 256M,其他语言512M
算法知识视频讲解
给定一个整数数组 nums 表示不同数额的硬币和一个正整数 target 表示总金额,请你计算并返回可以凑出总金额的的组合数。如果凑不出 target 则返回 0。
数据范围:数组长度满足
,数组中的数和 target 大小满足
示例1
输入
5,[1,2,4,5]
输出
5
示例2
输入
5,[4]
输出
0
示例3
输入
5,[5]
输出
1
马上挑战
算法知识视频讲解
提交运行
算法知识视频讲解
添加笔记
求解答(0)
邀请回答
收藏(76)
分享
纠错
提交结果有问题?
4个回答
9篇题解
开通博客
不会做题的小菜鸡
发表于 2022-03-03 10:15:45
题目分析 题目给出了一个target目标钱数,和一个nums数组,其中元素代表是硬币的币值 题目说不同硬币的币值可以无限次挑选 题目要求返回凑出target目标数的硬币挑选方案的数量 方法一:动态规划 实现思路 我们规定dp[i][j]表示在前i种硬币中挑选,凑出j的方案数,最终返回结果
展开全文
代码界的小白
发表于 2022-03-07 21:06:22
题目主要信息 给定一个整数数组 nums 表示不同数额的硬币和一个正整数 target 表示总金额,请你计算并返回可以凑出总金额的的组合数。如果凑不出 target 则返回 0 方法一:DFS 具体方法 使用DFS递归和回溯的方法。dfs方法中有三个参数,分别是nums数组,索引和target,在递
展开全文
burnian
发表于 2021-11-13 14:46:21
时间复杂度:O(mn),空间复杂度:O(n) 可以把总金额看做背包的容量,把不同面值的硬币看做待装的物品,因为凑出总金额的组合与顺序无关,即(1,2)和(2,1)凑出3属于同一种情况,所以该问题可以看做是完全背包问题的变种。本解法基于读者已经对背包问题有了一定程度的了解,所以给出的是经过了一维优化的
展开全文
dididididido
发表于 2023-05-20 15:30:07
时间复杂度O(nm), 空间复杂度O(nm)。考虑使用滚动数组思想,可以将空间复杂度优化到O(m)「C++ 代码」 class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * *
展开全文
youxiwang
发表于 2022-02-07 09:55:37
完全背包问题的变形。 input: 5,[1,2,4,5] vi dp[0 1 2 3 4 5] 0 1 0 0 0 0 0 1 1 1 1 1 1 1 2 1 1 2 2 3 3 4 1 1 2 2 4
展开全文
美子201907141638983
发表于 2022-05-13 19:56:37
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param target int整型 * @param
展开全文
改变眼泪的理由
发表于 2023-07-20 21:23:06
#include <vector> class Solution { public: //完全背包-种数-组合数 //dp[j]:总金额为j,在nums存储的硬币面额中,有dp[j]种 组合 方式。 //递推公式:求种数的问题,递推公式为dp[j]=dp[j] +
展开全文
红烧吹风机
发表于 2022-08-11 22:13:03
设dp[j]表示凑成j元一共有多少方法,dp[0] = 1,凑成0元只有一种方法,就是啥也不拿出来 转移方程:dp[j] = dp[j] + dp[j-nums[i]] 这里的dp表是由二维的dp表压缩成一维的,还有一层用第i个硬币的含义。假设计算用第i个硬币凑成j元时候,等号左边是等待更新的状态,
展开全文
AimerAimer
发表于 2022-03-09 22:17:59
题意: 给定一个整数数组 nums 表示不同数额的硬币和一个正整数 target 表示总金额,请你计算并返回可以凑出总金额的的组合数。 &nbs
展开全文
问题信息
动态规划
数组
难度:
4条回答
76收藏
1594浏览
热门推荐
通过挑战的用户
查看代码
已注销
2023-03-05 10:55:00
牛客59979...
2022-11-04 14:00:14
JhaStinger
2022-09-25 23:09:02
盛夏的泡沫
2022-09-16 12:57:20
ekile
2022-09-14 13:08:39
相关试题
设某二叉树的先序遍历序列为abdg...
树
评论
(1)
游戏内数据分析涉猎的少,如何证明自...
评论
(1)
之前的经历中单品数据分析的经验丰富...
评论
(1)
什么样的人适合做数据分析
评论
(1)
2022 诺瓦科技 Perl re...
perl
System Verilog
评论
(1)
扫描二维码,关注牛客网
意见反馈
下载牛客APP,随时随地刷题
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param target int整型 * @param nums int整型一维数组 * @return int整型 */ public int change (int target, int[] nums) { // write code here } }
class Solution { public: /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param target int整型 * @param nums int整型vector * @return int整型 */ int change(int target, vector
& nums) { // write code here } };
#coding:utf-8 # # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param target int整型 # @param nums int整型一维数组 # @return int整型 # class Solution: def change(self , target , nums ): # write code here
using System; using System.Collections.Generic; class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param target int整型 * @param nums int整型一维数组 * @return int整型 */ public int change (int target, List
nums) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param target int整型 * @param nums int整型一维数组 * @return int整型 */ function change( target , nums ) { // write code here } module.exports = { change : change };
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param target int整型 # @param nums int整型一维数组 # @return int整型 # class Solution: def change(self , target: int, nums: List[int]) -> int: # write code here
package main import "fmt" /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param target int整型 * @param nums int整型一维数组 * @return int整型 */ func change( target int , nums []int ) int { // write code here }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param target int整型 * @param nums int整型一维数组 * @param numsLen int nums数组长度 * @return int整型 */ int change(int target, int* nums, int numsLen ) { // write code here }
# # 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 # # # @param target int整型 # @param nums int整型一维数组 # @return int整型 # class Solution def change(target, nums) # write code here end end
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param target int整型 * @param nums int整型一维数组 * @return int整型 */ def change(target: Int,nums: Array[Int]): Int = { // write code here } }
object Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param target int整型 * @param nums int整型一维数组 * @return int整型 */ fun change(target: Int,nums: IntArray): Int { // write code here } }
import java.util.*; public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param target int整型 * @param nums int整型一维数组 * @return int整型 */ public int change (int target, int[] nums) { // write code here } }
/** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param target int整型 * @param nums int整型一维数组 * @return int整型 */ export function change(target: number, nums: number[]): number { // write code here }
public class Solution { /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param target int整型 * @param nums int整型一维数组 * @return int整型 */ func change ( _ target: Int, _ nums: [Int]) -> Int { // write code here } }
struct Solution{ } impl Solution { fn new() -> Self { Solution{} } /** * 代码中的类名、方法名、参数名已经指定,请勿修改,直接返回方法规定的值即可 * * * @param target int整型 * @param nums int整型一维数组 * @return int整型 */ pub fn change(&self, target: i32, nums: Vec
) -> i32 { // write code here } }
5,[1,2,4,5]
5
5,[4]
0
5,[5]
1